data(){
return {
clickTimer: null,
waitTime: 500, // 该时间间隔内点击才算连续点击(单位:ms)
lastTime: 0,
clickCount: 0, // 连续点击次数
}
},
methods(){
// 点击多次显示与隐藏
toShowAndHideRecord() {
var currentTime = new Date().getTime();
// 计算两次相连的点击时间间隔
this.clickCount =
currentTime - this.lastTime < this.waitTime ? this.clickCount + 1 : 1;
this.lastTime = new Date().getTime();
clearTimeout(this.clickTimer);
this.clickTimer = setTimeout(() => {
clearTimeout(this.clickTimer);
// 处理点击事件
console.log(this.clickCount, "次数");
if (this.clickCount > 2) {
console.log("点击次数超过3次,可以执行你想做的操作了");
}
}, this.waitTime + 10);
}
}