StarFire_xm
  • 文章
  • 粉丝
  • 评论

vue长按和点击共存

2021-07-20 11:04:390 次浏览0 次评论技能类型: vue
<div>
  <div @touchstart.prevent="touchin()" @touchend.prevent="clickhandle()" ></div>
</div>


data() {
  return {
    Loop:0
  }
},

methods: {
  touchin(index){ // 长按事件,按住后等待指定事件触发
    let that=this;
    this.Loop = setTimeout(function() {
      that.Loop = 0;
      console.log("长按触发")
    }, 500);
    return false;
 
  },
  clickhandle() { // 模拟点击事件(点击后迅速抬起)
    let that=this;
    clearTimeout(this.Loop);
    if(that.Loop!==0){
      console.log("点击事件")
    }
    return false;
  }
}


    发表

    还没有评论哦,来抢个沙发吧!