M
M
mazahaler2019-10-23 20:34:20
Vue.js
mazahaler, 2019-10-23 20:34:20

How to properly change store in Vuex?

Hello, the question is: how to change the data in the store correctly? Let me give you an example: now I have the following line in the component: Is it normal to do this? Or do I need to create a method in mutations specifically for this? How to do "ethically"?
this.$store.state.someArray.push(this.item)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-10-23
@mazahaler

You cannot change the state directly, for this there are mutations. The state can be changed (mutated) only with the help of a mutation. vuex has a strict mode that will throw an error on state changes outside of the mutation.
5db09079f1db0462563773.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question