vue页面切换,定时器组件不停止销毁问题

问题描述

某一页面组件内有一定时期,跳转到另一页面定时器依然运行

问题原因

页面销毁时定时器未停止

问题解决

// 通过$once来监听定时器,在beforeDestroy钩子可以被清除。
let t = setInterval(event, 1000)
this.$once('hook:beforeDestroy', () => {
    
                
    clearInterval(t);                                    
})

猜你喜欢

转载自blog.csdn.net/lorogy/article/details/108732374