初始化数据
data(){
return {
timer:null
}
}
请求
mounted(){
//登录后先请求 避免页面无数据
this.allGetMock();
//之后3秒自动刷新页面
this.timer = setInterval(() => {
this.allGetMock();
},3000);
}
销毁定时器
beforeDestroy(){
// 销毁定时器
this.$once('hook:beforeDestroy',() =>{
clearInterval(this.timer);
})
}