In my SPA made with VUE I have a component running a recursive few of setInterval functions (it's a countdown). I noticed the countdown continue in the background when I switch view to another component, but I prefer to destroy the setInterval.
I tried using a global data having the countdowns and then destroy it on destroyed hook but it doesn't work.
Here my code:
data: function () {
return {
counters: ""
}
}),
methods: {
countdown(index, exp) {
...
this.counters = setInterva()
...
},
},
destroyed(){
console.log(this.counters); // returns a progressive integer
clearInterval(this.counters);
console.log(this.counters); // returns same integer
this.counters = 0;
console.log("destroyed");
}
But in the console I got:
destroyed
app.js:64433 0
app.js:64398 Missing counter_1 . <--- which means counter is still running
Thanks for any suggestion!