From f3e9168e76d27cfb50bebe554095c754ae707399 Mon Sep 17 00:00:00 2001 From: zhangsir Date: Mon, 6 May 2024 15:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=AF=955=E7=A7=92=E5=86=85=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E6=8F=90=E4=BA=A4=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/study/exam.vue | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pages/study/exam.vue b/pages/study/exam.vue index d1bc2af..b7d9651 100644 --- a/pages/study/exam.vue +++ b/pages/study/exam.vue @@ -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,16 +352,16 @@ } }) }, - debounce(func, delay) { - let timerId; - return function (...args) { - if (timerId) clearTimeout(timerId); - timerId = setTimeout(() => { - func.apply(this, args); - timerId = null; - }, delay); - }; - }, + throttle(func, delay) { + let lastExecTime = 0; + return function (...args) { + const now = Date.now(); + if (now - lastExecTime >= delay) { + func.apply(this, args); + lastExecTime = now; + } + }; + }, present(){ let $this=this; let score=this.countTest();