首先看下触摸事件执行顺序:
touchstart → longtap → touchend → tap
所以长按事件也会触发点击事件是正常效果
如果一个对象同时绑定了tap和longtap事件,需求longtap时不触发tap事件可参考以下解决办法
<script>
let touching = true // 是否触发长按事件
tap(e) {
if(this.touching) return
// 逻辑处理
}
longtap(e) {
this.touching = true
// 逻辑处理
}
touchend(e) {
setTimeout(()=>{
touching = false
},200)
}
</script>