[Vuejs]-How to listen for changes in state object loaded from API?

0👍

Did you try to set the state using Vue.set?

Ref: https://vuex.vuejs.org/en/mutations.html

From the docs:

Mutations Follow Vue’s Reactivity Rules

Since a Vuex store’s state is made reactive by Vue…

When adding new properties to an Object, you should either: Use Vue.set(obj, 'newProp', 123) or …

You are adding new props here. You should set it as follows:

Vue.set(state, tools, response.tools)

0👍

For a more general answer, the syntax of Vue.set is:

Vue.set(object, key, value)

So if you use this somewhere at a deep level, you get:

let object = state.someLargeObject.SomeObjectInsideIt

Vue.set(object, key, value)

Leave a comment