一、需求
二、思路
结合 clearInterval 与 getCancelledNum 进行。
三、实现
methods() {
getCancelledNum() {
getCancelingNum().then((res) => {
this.cancelledNum = res.data;
this.isShow = true;
});
}
}
mounted() {
this.getCancelledNum();
this.timer = setInterval(() => {
this.getCancelledNum();
}, 300000);
}
destroy() {
clearInterval(this.timer);
}
activated() {
this.getCancelledNum();
clearInterval(this.timer);
this.timer = setInterval(() => {
this.getCancelledNum();
}, 300000);
}
deactivated() {
clearInterval(this.timer);
}