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