[Vuejs]-How to include promises in vuejs methods

0👍

The problem is with the if (this.done) check.
When done is false, the promise is never resolved, and the handleStart never receives data.

If you need to react when a data has changed, take a look Vue’s watchers

0👍

you need to use watchers to watch this.done change

watch: {
  done(newVal, oldVal) {
    if (newVal) {
      // do something
    }
  }
}, 
methods: {
  async handleStart () {
    // how to make this async
    this.start = true
    const data = await this.foo()
    console.log("I must be printed with:", data))
  }
}

Leave a comment