小程序图片选择器
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201109153915762.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyOTIxOQ==,size_16,color_FFFFFF,t_70#pic_center)
<view class="selectImg">
<view class="imgPic" wx:key="images" wx:for="{{images}}">
<image src="{{item}}"></image>
<view class="img-de" data-deindex='{{index}}' bindtap='imgDelete1'><image class='img' src='../../images/del-img.png' style="width:100%;height:100%;"></image></view>
</view>
<view bindtap='selectImg' wx:if="{{images.length<9}}">
<image src="../../images/img-ic.png"></image>
</view>
</view>
selectImg: function(e) {
var _this = this;
var imgbox = _this.data.images;
var picid = e.currentTarget.dataset.pic;
console.log(picid)
var n = 9;
if (9 > imgbox.length > 0) {
n = 9 - imgbox.length;
} else if (imgbox.length == 9) {
n = 1;
}
wx.chooseImage({
count: n,
success: function(res){
var tempFilePaths = res.tempFilePaths
if (imgbox.length == 0) {
imgbox = tempFilePaths
} else if (9 > imgbox.length) {
imgbox = imgbox.concat(tempFilePaths);
} else {
imgbox[picid] = tempFilePaths[0];
}
_this.setData({
images: imgbox
});
},
fail:function(res) {
console.log(res.errMsg)
}
})
},
imgDelete1: function (e) {
let that = this;
let index = e.currentTarget.dataset.deindex;
let imgbox = this.data.images;
imgbox.splice(index, 1)
that.setData({
images: imgbox
});
},```