<view class="weui-cell"> <view class="weui-cell__bd"> <view class="weui-uploader"> <view class="weui-uploader__hd"> <view class="weui-uploader__title">当前设备照片</view> <view class="weui-uploader__info">{{current.length}}/3</view> </view> <view class="weui-uploader__bd"> <view class="weui-uploader__files" id="uploaderFiles"> <block wx:for="{{current}}" wx:key="*this"> <view class="weui-uploader__file" bindlongpress="currentDelImg" data-index="{{index}}"> <image class="weui-uploader__img" src="{{item}}" id="{{item}}" bindtap="currentPreviewImage" mode="aspectFill" /> </view> </block> </view> <view class="weui-uploader__input-box" wx:if="{{current.length < 3}}"> <view class="weui-uploader__input" bindtap="currentChooseImage"></view> </view> </view> </view> </view> </view>
/* 删除图片 */ currentDelImg: function (e) { var that = this; var current = that.data.current; var index = e.currentTarget.dataset.index;//获取当前长按图片下标 wx.showModal({ title: '提示', content: '确定要删除此图片吗?', success: function (res) { if (res.confirm) { console.log('点击确定了'); current.splice(index, 1); } else if (res.cancel) { console.log('点击取消了'); return false; } that.setData({ current }); } }) }