Reset Interval #58
-
I'm running an $interval, and I had to reset its value when the user clicks. Those helpers would save me a lot of code (adding more variables and timers and booleans to achieve the above). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can clear the timer on click with something like Internally, there's a watcher for that property this.$watch('autoIntervalTest', test => {
if (test) {
this.autoIntervalLoop = loop
forceInterval ? this.autoIntervalLoop() : requestAnimationFrame(this.autoIntervalLoop)
} else {
clearTimeout(this.autoIntervalLoop)
this.autoIntervalLoop = null
}
}) |
Beta Was this translation helpful? Give feedback.
-
Oh lovely, that was what I needed actually. |
Beta Was this translation helpful? Give feedback.
You can clear the timer on click with something like
<button @click="autoIntervalTest = false">
and you could abstract that to a function that will set it to true after 2 seconds.Internally, there's a watcher for that property