fix(study): 优化视频定时器处理并添加路由离开清理
确保在组件销毁和路由离开时都清除视频定时器,避免内存泄漏。简化视频当前时间获取逻辑,移除不必要的条件判断。
This commit is contained in:
parent
fc801620c0
commit
2704846056
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user