Suppose a store like this
...
state: {
filters: {
a: '',
b: ''
}
},
mutations: {
updateFilters(state, newObject) {
state.filters = newObject
}
}
...
And a component like this
...
<input v-model='filters.a'></input>
...
computed: {
filters: {
get() {
this.$store.state.filters
}
set(value) {
this.$store.commit('updateFilters', value)
}
}
}
...
Everything works fine but I see a warning saying
Error: "[vuex] do not mutate vuex store state outside mutation handlers."
So I'm obviously missing something
I don't understand how to handle this. Can someone explain how to mutate a state object in a component?
I know, I can mutate every filters prop, but I have a LOT of filters in that object, so mutate every single prop is not the best solution in this case.
state.filters ={newObject}
you are getting the same warning? – Raffobaffo