The page in vue is destroyed, and the timer is still going?

1: in mounted () {

this.timer = setInterval(() => {
    this.rechargeInfo();
}, 3000);

} create a timer.
2:
beforeDestroy () {

when the aspect route is redirected
this.timer = null;
clearInterval(this.timer);

},
destroyed () {

this.timer = null;
clearInterval(this.timer);

} to clear
.
in theory, the timer is cleared when the component is destroyed. ,
but: the timer is still running when you jump to another page.
question.


this.timer = null;
clearInterval(this.timer);

is it in reverse order. If you write clearInterval in this way, the parameter is null how can you destroy the timer correctly

clearInterval(this.timer);
this.timer = null;

try it like this


you want to call the destroy hook destroy clearing timer


this.timer = null; this has affected, just remove it

Menu