微信小程序 长按事件 删除图片

1:页面代码

<view class="uploader__files">

<block wx:for="{{images}}" wx:key="{{item.id}}" >

<view class="uploader__file" bindlongpress="deleteImage" data-index="{{index}}">

<image mode="aspectFill" class="uploader__img" src="{{item}}" />

</view>

</block>

</view>

 

2:js代码 

deleteImage: function (e) {
    var that = this;
    var images = that.data.images;
    var index = e.currentTarget.dataset.index;//获取当前长按图片下标
    wx.showModal({
      title: '提示',
      content: '确定要删除此图片吗?',
      success: function (res) {
        if (res.confirm) {
          console.log('点击确定了');
          images.splice(index, 1);
        } else if (res.cancel) {
          console.log('点击取消了');
          return false;
        }
        that.setData({
          images
        });
      }
    })
  }

要点:

1:长按事件是用bindlongpress(不会跟点击事件bindtap冲突);

posted @   码奴生来只知道前进~  阅读(134)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示