直接上代码,以下
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();
}


Logo

前往低代码交流专区

更多推荐