5秒内点击只生效一次

This commit is contained in:
zhangsir
2024-05-06 15:08:00 +08:00
parent 10129e8b4f
commit 483f44cb0e

View File

@@ -92,8 +92,8 @@
if(this.examId){
this.loadExamInfo();
}
this.debouncedPresent = this.debounce(this.present, 500);
this.confirmStop = this.debounce(this.submitTest,500)
this.debouncedPresent = this.throttle(this.present, 5000);
this.confirmStop = this.throttle(this.submitTest,5000)
},
methods: {
changeTimer(){
@@ -352,14 +352,14 @@
}
})
},
debounce(func, delay) {
let timerId;
throttle(func, delay) {
let lastExecTime = 0;
return function (...args) {
if (timerId) clearTimeout(timerId);
timerId = setTimeout(() => {
const now = Date.now();
if (now - lastExecTime >= delay) {
func.apply(this, args);
timerId = null;
}, delay);
lastExecTime = now;
}
};
},
present(){