0 votes
in VueJS by

What are the caveats with vuex mutations?

1 Answer

0 votes
by

Since a Vuex store's state is made reactive by Vue, the same reactivity caveats of vue will apply to vuex mutations. These are the rules should be followed for vuex mutations,

  1. It is recommended to initialize store's initial state with all desired fields upfront
  2. Add new properties to state Object either by set method or object spread syntax
    Vue.set(stateObject, 'newProperty', 'John')
    (OR)
    state.stateObject = { ...state.stateObject, newProperty: 'John' }

Related questions

0 votes
asked Sep 10, 2023 in VueJS by DavidAnderson
0 votes
asked Sep 9, 2023 in VueJS by DavidAnderson
...