记得之前有同事说过处理双击事件,然后听了个大概,这次用到了,记录下
定义点击时间
data() {
return {
video_url:'',
screenHeight:'',
touchStartTime:0
};
},
然后点击时执行,判断当前时间与点击时间的差值
let that = this;
let now_time = new Date().getTime();
if(now_time - this.touchStartTime < 350){
console.log("双击");
uni.showToast({
title:'双击',
icon:'none'
})
}else{
console.log("单击");
this.touchStartTime = new Date().getTime()
}
三击的话会多一个点击次数判断,但是一个按钮上同时又单击、双击、三击时候会有问题,目前没想到思路,只能遇到这种需求时候再想了
var that= this;
let now_time = new Date().getTime();
this.t_click +=1;
if(now_time - this.touchStartTime < 550 && this.t_click ==3 ){
console.log("三击");
}else{
if(now_time - this.touchStartTime < 350 ){
console.log("双击");
}
}
if(now_time - this.touchStartTime >600){
console.log("单击");
this.touchStartTime = new Date().getTime()
setTimeout(function(){
that.t_click = 0;
console.log('clear');
},1000)
}