karambaq
karambaq

Reputation: 861

Vuex + vue not reactive when using dictionary as state object

I need to use dictionary as one of my store variables, but It's not reactive like array, what is the best practice to solve this? I've created minimal example:

https://codesandbox.io/s/vuex-store-forked-ko3md?file=/src/App.vue

Upvotes: 2

Views: 1753

Answers (1)

Igor Moraru
Igor Moraru

Reputation: 7729

In order to add new reactive props, instead of using direct assignment, you should use the Vue.set() method:

  ADD_ITEM(state, { key, value }) {
    Vue.set(state.dict, key, value)
  }

For a more in dept understanding of Vue reactivity you should read the official docs: https://v2.vuejs.org/v2/guide/reactivity.html

Upvotes: 6

Related Questions