2020
10-08
10-08
解决vue组件销毁之后计时器继续执行的问题
直接上代码,以下window.setTimeout(function(){if(this&&!this._isDestroyed){//_isDestroyed组件是否被销毁return;}window.location.href="/serverMonitor?t="+newDate().getTime();},5000)很粗暴的方法,在执行之前看是否被销毁就行,第二种方法,调用路由组件内的钩子函数beforeRouteLeavebeforeRouteLeave(to,from,next){clearTimeout(window.timer);next();}补充知识:vue销毁时事件,created...
继续阅读 >