I'm constantly getting the "[vuex] do not mutate vuex store state outside mutation handlers." error on my application. When I use a getter inside a component, I solve it destructuring the getter, something like:
const user = {
...this.$store.getters["Users/getUser"]
};
But sometimes, when I need to use something of my store state, inside a Vuex action, the only wat to "unbind" the object is using JSON.parse(JSON.stringify(state.something)), because destructuring still returns Vuex mutation error, and using the JSON.stringify and JSON.parse is probably the wrong way:
setActiveUser({ commit, state }, payload) {
return new Promise((resolve, reject) => {
let newUser = JSON.parse(JSON.parse(state.user))
etc
});
}
What is the correct way to unbind my state?
Thank you.