提交 577bad68 编写于 作者: laizhilong's avatar laizhilong

销毁前清除定时器

上级 6739e867
......@@ -79,15 +79,13 @@
public myTasksLabel: any = "待办";
// 消息列表
public myMsgs: any = [];
// 消息列表标签
// 消息面板标签
public myMsgsLabel: any = "消息";
/**
* vue创建
*/
created(): void {
}
created(): void {}
/**
* vue挂载
......@@ -96,11 +94,16 @@
// 第一次获取待办列表
this.getMyTasks();
let count = 1;
// 每隔1分钟重新获取待办列表
setInterval(()=>{
// 定时器:每隔1分钟重新获取待办列表
const timer = setInterval(()=>{
this.getMyTasks();
count++;
},1000*60);
},5000);
// 监听定时器,在vue销毁前清除定时器
this.$once('hook:beforeDestroy',()=>{
// 清除定时器
clearInterval(timer);
});
}
/**
......@@ -136,7 +139,6 @@
}
}
/**
* 点击标签事件
*/
......@@ -153,6 +155,7 @@
* 销毁之前
*/
beforeDestroy(): void {
// 清空数据
this.showIsDot = false;
this.myTasks = [];
this.myMsgs = [];
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册