[Vuejs]-Cannot update vue data inside function while fetching?

0👍

Your problem here (likely) is due to the fact that you are calling the fetchWords() function before the component renders, but not telling it to re-render after the data is retrieved. By that point in time, Vue has no idea that you were triggering a "redraw". You have two options:

  1. You can use the mounted() (Vue Lifecycle Hooks) lifecycle hook and then your data will be requested as soon as Vue.js mounts the component and then it will know to reset that data point.
  2. You can call the this.nextTick() function (nextTick() reading) to force Vue.js to "redraw" the UI.

This is all still a guess, but that’s what I have seen thus far when dealing with HTTP and the Vue.js lifecycle hooks.

Leave a comment