当前位置:网站首页>[wechat applet] the mobile terminal selects and publishes pictures
[wechat applet] the mobile terminal selects and publishes pictures
2022-06-12 04:23:00 【Juvenile song line s】
The finished picture is as follows


This article mainly describes the implementation of the function of selecting pictures .
principle :
// html
<view class="chooseImageBox">
<!-- Render selected pictures -->
<block wx:for="{
{photo}}" wx:key="photoIndex">
<view class="beChoosen_ImageBox">
<image class="beChoosen_Image" src="{
{item.tempFilePath}}" bindtap="preViewImage" data-index="{
{index}}" mode="aspectFill"></image>
<view class="del_beChoosen_Image" bindtap="del_beChoosen_Image" data-index="{
{index}}">×</view>
</view>
</block>
<!-- Click to select a picture -->
<view class="chooseImage" bindtap="chooseImage">
<image src="./images/jia.png"></image>
</view>
</view>
Before the user selects the picture , Variable photo Empty array . After the user selects the picture , Store the image cache address in the variable , You can render the selected picture . And select the picture button to move back .
besides , There is also a picture preview function 、 Delete picture function , The principle will not be repeated .
If you don't understand the code, you can ask questions in the comment area .
All the codes are as follows :
// Click event - Select Picture
chooseImage(){
let that = this;
wx.chooseMedia({
// To upload pictures
count: 6,
mediaType:'image',
sourceType:['album','camera'],
sizeType: ['original', 'compressed'], // The original drawing can be selected 、 Compressed graph
success: (res) => {
let photo = that.data.photo.concat(res.tempFiles);
wx.getImageInfo({
// Get picture information
src: photo[0].tempFilePath,
success: (res) => {
photo[0].imageHeight = res.height;
photo[0].imageWidth = res.width;
that.setData({
photo })
}
})
}
})
},
// Click event - Delete pictures
del_beChoosen_Image(e) {
let index = e.target.dataset.index; // Photo index value
let photo = this.data.photo.slice();
photo.splice(index,1); // Be careful :splice The return value is the deleted element , And change the original array
this.setData({
photo });
},
// Click on the selected picture - To preview
preViewImage(e) {
let urls = this.data.photo.map(item => {
return item.tempFilePath
});
let index = e.target.dataset.index;
wx.previewImage({
urls: urls,
current: urls[index]
})
},
// css .chooseImageBox {
display: flex;
flex-direction: row;
align-items: center;
}
.beChoosen_ImageBox {
display: inline-block;
position: relative;
width: 150rpx;
height: 150rpx;
margin-right: 20rpx;
}
.beChoosen_Image {
width: 150rpx;
height: 150rpx;
border-radius: 15rpx;
}
.del_beChoosen_Image {
position: absolute;
top: 5rpx;
right: 5rpx;
display: flex;
justify-content: center;
align-items: center;
width: 25rpx;
height: 25rpx;
border-radius: 50%;
background-color: rgb(10, 10, 10,0.3);
font-size: 25rpx;
color: #fff;
}
.chooseImage {
width: 150rpx;
height: 150rpx;
background-color: rgb(245, 245, 245);
border-radius: 15rpx;
display: inline-flex;
justify-content: center;
align-items: center;
}
.chooseImage image {
display: inline-block;
width: 60rpx;
height: 60rpx;
}
边栏推荐
- How do I extract files from the software?
- What does kotlin collaboration scope and coroutinescope mainscope globalscope viewmodelscope lifecyclescope represent respectively
- 图解 Apache SkyWalking UI 的使用
- Webpack--- optimization_ cache
- 手动封装一个forEacht和Map
- R语言write函数:使用write函数将数据写入RStudio控制台、write函数将数据写入新的Rstudio窗口(启动新的窗口)
- [MySQL] MySQL installation
- R语言plotly可视化:plotly可视化基础二维直方图、自定义设置二维直方图的颜色、二维直方图是二元分布的直方图可视化(Basic 2D Histogram)
- Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application
- Work report of epidemic data analysis platform [42] codenet
猜你喜欢
![[软件工具][原创]voc数据集类别名批量修改工具使用教程](/img/25/31d771c9770bb7f455f35e38672170.png)
[软件工具][原创]voc数据集类别名批量修改工具使用教程

How to have peace of mind? Get a new heart

JSP implementation of bank counter business performance evaluation system

D1 哪吒开发板 上电记录

D1 Nezha development board power on record

1. Mx6ull learning notes (III) - busybox creates root file system
![[software tool] [original] tutorial on using VOC dataset class alias batch modification tool](/img/25/31d771c9770bb7f455f35e38672170.png)
[software tool] [original] tutorial on using VOC dataset class alias batch modification tool

19.tornado项目之优化数据库查询

JSP实现银柜台业务绩效考核系统

【FPGA混沌】基于FPGA的混沌系统verilog实现
随机推荐
R语言write函数:使用write函数将数据写入RStudio控制台、write函数将数据写入新的Rstudio窗口(启动新的窗口)
Is there a row limit for a single MySQL table
Solution to missing in unity script
The memory four area model of C language program
Raspberry pie 4B uses Intel movidius NCS 2 for inference acceleration
Oracle:decode function
WPF data binding (IV)
如何制作数据集并基于yolov5训练成模型并部署
分布式锁介绍
La mise en évidence de la recherche par blocs est - elle prise en charge dans les versions ultérieures?
疫情数据分析平台工作报告【2】接口API
Kill session? This cross domain authentication solution is really elegant!
How do I extract files from the software?
MongoDB精华总结
QT compiling security video monitoring system 43- picture playback
What does hard work mean to you?
【FPGA混沌】基于FPGA的混沌系统verilog实现
Encapsulation manuelle d'un foreach et d'une carte
Illustrating the use of Apache skywalking UI
DS18B20数字温度计 (一) 电气特性, 供电和接线方式