Vue js triggering a method/function every x seconds

Just to combine the solutions (since I’m unable to edit), the code below works. One gotcha is that you also want the job to stop once the view is destroyed, so you’ll want to clear it when the beforeDestroy hook is called

mounted: function () {
  this.timer = setInterval(() => {
    this.countDown()
  }, 1000)
},

data() {
  return {
    timer: null
  }
},

beforeDestroy() {
  clearInterval(this.timer)
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)