vue文件
如果需要同时使用长按事件,和点击事件,此时@touchstart和@click同时使用的话,@click会失效,因为使用@touchstart会触发@click
首先在标签里实现长按事件,引用触发开始事件,触发结束事件
<view id="noticelist" v-for="(item,i) in notifyContent" @touchstart.prevent="touchin(i)" @touchend.prevent="cleartime(item.id)" >
只实现长按事件
touchin(noticeId) {
this.index = noticeId;
clearTimeout(this.Loop);
this.Loop = setTimeout(function() {
this.show = true;
}.bind(this), 1000);
},
cleartime(noticeId) {
this.id = noticeId;
clearTimeout(this.Loop);
},
如果长按事件和点击事件同时进行,需要声明一个变量
export default {
data() {
return {
Loop: 0
}
},
touchin(noticeId) {
this.index = noticeId;
clearTimeout(this.Loop);
//长按事件的实现
this.Loop = setTimeout(function() {
this.Loop = 0;
this.show = true;
}.bind(this), 1000);
},
cleartime(noticeId) {
this.id = noticeId;
clearTimeout(this.Loop);
//click点击事件的实现
if(this.Loop !== 0){
uni.navigateTo({
url: 'notifyDetail?id='+ noticeId
});
}
},