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

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

View File

@ -357,11 +357,7 @@ export default {
// //
function timer() { function timer() {
// console.log(""); // console.log("");
const video = document.getElementById("video"); let curTime = document.getElementById("video").currentTime;
let curTime;
if(video) {
curTime = video.currentTime;
}
let apartTime = curTime - _this.current_sign; let apartTime = curTime - _this.current_sign;
if (apartTime > 2 && _this.section[_this.choose_section_index].is_end != 1) { if (apartTime > 2 && _this.section[_this.choose_section_index].is_end != 1) {
@ -872,6 +868,14 @@ export default {
} }
}, },
}, },
beforeRouteLeave(to, from, next) {
//
if (this.video_timer) {
clearInterval(this.video_timer);
this.video_timer = null; //
}
next();
},
beforeDestroy() { beforeDestroy() {
if (this.video_timer) { if (this.video_timer) {
clearInterval(this.video_timer); clearInterval(this.video_timer);