I'm facing a problem where an Interval from a Vue component keeps running when I navigate to another route of my app.
I'm using Vue router, having the next configuration:
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/login',
name: 'Login',
component: LoginMenu
},
{
path: '/canvas',
name: 'Canvas',
component: AllElement
},
{
path: '/querybuilder',
name: 'QueryBuilder',
component: QueryBuilder
},
{
path: '/dashboard',
name: 'Dashboard',
component: Dashboard
}
]
The interval is in the AllElement component. As I'm using Vue router, AllElement is loaded into the router-view, and when I switch to Home.vue component, it will be loaded into the router-view but the AllElement's interval will keep running.
Here's where the interval is being initiated
mounted() {
this.fetchLastBucketData();
setInterval(() => {
this.fetchLastBucketData();
}, 3000);
}
Any solutions?