From 2704846056273fc8298dc3ee6510547b2814fd3b Mon Sep 17 00:00:00 2001 From: yindongqi Date: Fri, 15 Aug 2025 14:47:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(study):=20=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=AE=9A=E6=97=B6=E5=99=A8=E5=A4=84=E7=90=86=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1=E7=A6=BB=E5=BC=80=E6=B8=85?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 确保在组件销毁和路由离开时都清除视频定时器,避免内存泄漏。简化视频当前时间获取逻辑,移除不必要的条件判断。 --- src/components/study/courseDetail.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/study/courseDetail.vue b/src/components/study/courseDetail.vue index 030a134..f180b0f 100644 --- a/src/components/study/courseDetail.vue +++ b/src/components/study/courseDetail.vue @@ -343,11 +343,7 @@ export default { // 定时器 function timer() { // console.log("被调用了"); - const video = document.getElementById("video"); - let curTime; - if(video) { - curTime = video.currentTime; - } + let curTime = document.getElementById("video").currentTime; let apartTime = curTime - _this.current_sign; if (apartTime > 2 && _this.section[_this.choose_section_index].is_end != 1) { @@ -858,6 +854,14 @@ export default { } }, }, + beforeRouteLeave(to, from, next) { + // 确保离开路由时清除定时器 + if (this.video_timer) { + clearInterval(this.video_timer); + this.video_timer = null; // 重置定时器变量 + } + next(); + }, beforeDestroy() { if (this.video_timer) { clearInterval(this.video_timer);