Answer the question
In order to leave comments, you need to log in
Execute method after n-interval of time, but only after first event?
Hey!
There is an @click event that calls the doSomething() method .
The goal is to let the method execute immediately, but only on the first time/click. And in subsequent times / clicks, execute this method through setInterval.
How to implement it?
PS: I'm intricate, of course ...
Answer the question
In order to leave comments, you need to log in
Create a flag, set it to false, change it to true on the first click, and start the interval.
more or less like this:
data(){
return {
flag: false,
}
},
methods: {
somefunc(){
if(this.flag == false) {
//do something
//то что выполнится в первый раз
} else {
setInterval(func,5000);
// то что будет выполняться следующие разы
}
this.flag = true;
}
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question