[Vuejs]-Mutate vuex state object outside of store

0👍

The problem is that your setter never gets called. The getter is used, but a is updated directly.

Here is one option:

<input :value="filters.a" @input="updateFilterA"></input>
...
computed: {
  filters() {
    return this.$store.state.filters /* or mapState */
  }
},
methods: {
  updateFilterA(value) {
    this.$store.commit("updateFilterA", value)
  }
}

And in the store:

mutations: {
  updateFilterA(state, newValue) {
    state.filters.a = newValue
  }
}

Leave a comment