uni-app 小程序双击事件

uni-app 小程序双击事

目前uni-app view标签不支持双击事件,下面自定义双击事件:

// A code block
<view  @click="handClick(index)"></view>
data(){
    
    
  return {
    
    
    lastTapTimeoutFunc:null,
	lastTapDiffTime:0
  }
},

methods:{
    
    
// 单击或双击
handClick(index) {
    
    
  let _this = this;
  let curTime = new Date().getTime();
  let lastTime = _this.lastTapDiffTime;
  _this.lastTapDiffTime = curTime;
  //两次点击间隔小于300ms, 认为是双击
  let diff = curTime - lastTime;
  if (diff < 300) {
    
    
   	console.log("双击")
   	//_this.handleVideo('screen',index)自定义事件
   clearTimeout(_this.lastTapTimeoutFunc); // 成功触发双击事件时,取消单击事件的执行
 } else {
    
    
  // 单击事件延时300毫秒执行
   _this.lastTapTimeoutFunc = setTimeout(function() {
    
    
   	console.log("单击")
   //_this.handleVideo('playOrStop',index)自定义事件
   	}, 300);
 } 			
}
}

猜你喜欢

转载自blog.csdn.net/yuwenwenwenwenyu/article/details/113373886