关于vue组件销毁之后计时器继续执行的解决办法
直接上代码,以下window.setTimeout(function(){if(this && !this._isDestroyed){ //_isDestroyed 组件是否被销毁return;}window.location.href = "/serverMonitor?t="+ new Date().getTime();},5...
·
直接上代码,以下
window.setTimeout(function(){
if(this && !this._isDestroyed){ //_isDestroyed 组件是否被销毁
return;
}
window.location.href = "/serverMonitor?t="+ new Date().getTime();
},5000)
很粗暴的方法,在执行之前看是否被销毁就行,
第二种方法,调用路由组件内的钩子函数beforeRouteLeave
beforeRouteLeave(to,from,next){
clearTimeout(window.timer);
next();
}
更多推荐
已为社区贡献5条内容
所有评论(0)