Using Actions to Mutate the State
As of now, you have the data of the application stored in the state and read in the component’s view. Bue, what if you want to edit that data? Well, you can do so easily with something called, actions
and mutations
.
As stated before (eh, state? okay, moving on...) state management is confusing at first. Like everything, there is an “ah hah!” moment where everything makes perfect sense. One of the more difficult things to wrap your head around at first is, “Why have actions and mutations? I just want to edit the data directly”. That’s a good question. The reason for the additional steps is that you want your state and it’s mutations to be tracked. Meaning, you want every change to be intentional. It helps reduce errors and bugs as the application grows.
In short...your actions
perform logic and sends the modified data (if applicable) to the mutation
so the mutation can replace the state property with the...