[Vuejs]-VueJs – Vuex – Change a state

3👍

the state.mode += ''; doesn’t change any thing in the state, it just add an empty string the right way is to mutate it using assignment = using the payload:

this.$store.commit('change', newValue?'light':'dark');

then inside the mutation :

  mutations: {
    change (state, mode) {
      state.mode =mode;
    }
  },

Leave a comment