给你个参考吧:
// 删除图片
TrashImg: function (e) {
var arr = []
for (var i = 0; i < this.data.imgList.length; i++) {
if (i != e.target.dataset.idx)
arr.push(this.data.imgList[i])
}
this.data.imgList = arr
this.setData({
imgList: this.data.imgList,
uploadMore: true
})
}
然后把 TrashImg 放在图片上:
<view class=‘upload-list’>
<block wx:for-items=’{{imgList}}’ wx:key=‘imgList’ wx:for-index=‘idx’>
<view class=‘upload-item upload-image’>
<image src=’{{item}}’ bindlongpress=‘TrashImg’ data-idx=’{{idx}}’ mode=‘aspectFit’ />
</view>
</block>
<view class=‘upload-item btn-upload’ wx:if=’{{uploadMore}}’>
<text bindtap=‘ChooseImg’></text>
</view>
</view>