[Vuejs]-How to set a watch property for current time and initiate an action in Vue js

2👍

You can try to instead create data property currentTime:

data() {
  return {
    currentTime: 0
  }
},

Then on mounted hook set interval, update and watch currentTime from data:

mounted: function () {
  window.setInterval(() => {
    this.currentTime = new Date()
  }, 1000)
}, 

watch: {
  async currentTime(newValue, oldValue) {
    ...

Leave a comment