aujau
aujau

Reputation: 87

setInterval on child component method called with refs to child at parent component

I want to execute setInterval in the child component from the parent component. When I do console.log in start it appears in the console, however the interval doesn't start. If I call the method in child component, then it works.

Child methods:

stop() {
     clearInterval(this.t);
        },
start() {
     this.timer = setInterval(() => {this.call()}, 1000);
}

Parent method:

methods: {
    update() {
       this.$refs.childComponent.start();
    },
}

Upvotes: 0

Views: 786

Answers (1)

LarrySSS
LarrySSS

Reputation: 50

Do not use arrow function in setInterval, it won't clear. You can do like this example

Upvotes: 1

Related Questions