微信小程序绑定长按与单击事件

为需要添加长按事件的组件添加以下四个事件


  组件中的内容

其中

  • bindtouchstart:触屏开始时间
  • bindtouchend :触屏结束时间
  • bindlongtap:绑定长按事件
  • catchtap:单击事件

长按事件会触发单击事件,文档中说不会,操作中确实是触发了,所以在单击事件中加个判断,当触屏时间小于350ms才会触发单机事件(长按事件在触屏时间大于350ms时会自动触发):

  mytouchstart: function (e) {  //记录触屏开始时间
    this.setData({start:e.timeStamp })
  },
  mytouchend: function (e) {  //记录触屏结束时间
    this.setData({end: e.timeStamp })
  }, 
 deleteitem:function(e) {  长按事件内容   }
 onLinkDatail:function(e) {
   if (_that.data.end - _that.data.start < 350){
      单击事件内容
   }
}

完成!亲测可用

你可能感兴趣的:(微信小程序绑定长按与单击事件)