fix(study): 优化视频定时器处理并添加路由离开清理

确保在组件销毁和路由离开时都清除视频定时器,避免内存泄漏。简化视频当前时间获取逻辑,移除不必要的条件判断。
This commit is contained in:
yindongqi 2025-08-15 14:47:29 +08:00
parent fc801620c0
commit 2704846056

View File

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