1: 在mounted() {this.timer = setInterval(() => { this.rechargeInfo();
}, 3000);}創(chuàng)建一個定時器。2: 切面路由跳轉(zhuǎn)的時候beforeDestroy() {this.timer = null;
clearInterval(this.timer);},destroyed() {this.timer = null;
clearInterval(this.timer);} 進行清除。。。理論上組件銷毀的時候定時器已經(jīng)清除了。、但是: 跳到其他頁面的時候定時器依然在走。疑問。
1 回答

天涯盡頭無女友
TA貢獻1831條經(jīng)驗 獲得超9個贊
this.timer = null; clearInterval(this.timer);
順序反了吧,你這樣寫clearInterval
的參數(shù)是null
怎么能正確銷毀計時器呢
clearInterval(this.timer);this.timer = null;
改成這樣試下
添加回答
舉報
0/150
提交
取消