1、在activated中使用, 关闭或者离开当前页则不调用了
data() {
return {
timer: null
}
}
async activated() {
await this.getQuery()
this.getData(this.getQuery())
this.timer = setInterval(() => {
this.getData(this.getQuery())
}, 1000)
},
deactivated() {
clearInterval(this.timer);
this.timer = null;
},
2、在methods中使用,在destroyed清除,关闭或者离开当前页还继续执行
//重置筛选条件
resetSearch() {
this.timer = setInterval(() => {
console.log("你好啊");
}, 500);
this.form.resetFields()
},
destroyed() {
clearInterval(this.timer);
this.timer = null;
},
//重置筛选条件
resetSearch() {
this.timer= setInterval(() => {
console.log("你好啊");
}, 500);
this.$once('hook:beforeDestroy', () => {
clearInterval(this.timer);
})
},
当你还不够足够优秀时,请继续多学习,多看书!