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);
}
}
}