1: 在mounted() {
this.timer = setInterval(() => {
this.rechargeInfo();
}, 3000);
}创建一个定时器。
2: 切面路由跳转的时候
beforeDestroy() {
this.timer = null;
clearInterval(this.timer);
},
destroyed() {
this.timer = null;
clearInterval(this.timer);
} 进行清除
。。。
理论上组件销毁的时候定时器已经清除了。、
但是: 跳到其他页面的时候定时器依然在走。
疑问。
顺序反了吧,你这样写
clearInterval
的参数是null
怎么能正确销毁计时器呢改成这样试下