為需要添加長按事件的組件添加以下四個事件
<view class='oneofnotice' catchtap="onLinkDatail" bindtouchstart="mytouchstart" bindlongtap="deleteitem" bindtouchend="mytouchend">
組件中的內(nèi)容
</view>
其中
- bindtouchstart:觸屏開始時間
- bindtouchend :觸屏結(jié)束時間
- bindlongtap:綁定長按事件
- catchtap:單擊事件
長按事件會觸發(fā)單擊事件,文檔中說不會,操作中確實是觸發(fā)了,所以在單擊事件中加個判斷攀唯,當(dāng)觸屏?xí)r間小于350ms才會觸發(fā)單機(jī)事件(長按事件在觸屏?xí)r間大于350ms時會自動觸發(fā)):
mytouchstart: function (e) { //記錄觸屏開始時間
this.setData({start:e.timeStamp })
},
mytouchend: function (e) { //記錄觸屏結(jié)束時間
this.setData({end: e.timeStamp })
},
deleteitem:function(e) { 長按事件內(nèi)容 }
onLinkDatail:function(e) {
if (_that.data.end - _that.data.start < 350){
單擊事件內(nèi)容
}
}
完成!親測可用