Defining actions and mutations
It's great that our components can now get data from the store, but it would be probably even more interesting if our components were also able to change the data in the store. On the other hand, we all know that we cannot modify the store's state directly.
The state should not be touched by any of the components. However, you also remember from our chapter about the Vuex store that there are special functions that can mutate the store. They are even called mutations
. These functions can do whatever they/you want with the Vuex store data. These mutations can be called using the commit
method applied to the store. Under the hood, they essentially receive two parameters – the state and the value.
I will define three ...
Get Vue.js 2 and Bootstrap 4 Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.