Vuex Executing Function After Async State Change Vuex Executing Function After Async State Change vue.js vue.js

Vuex Executing Function After Async State Change


The watch never fires because the code is watching the object returned from getItem, which is the state object and the reference to the state object doesn't change. Only the state object's properties change. If you want to fire the watch, you need to perform a deep watch.

watch:    {  item: {    handler:function (newItem) {      this.doSomethingWith(newItem);    },    deep:true  }},

Depending on your application this might not be very performant. You might want to use a getter that watches a specific property of the state.

Or, return a promise from an action that kicks off the asynchronous API call and do what you need to in a success handler.