From the course: Building Laravel and Vue.js 2 Web Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Dispatching Vuex actions

Dispatching Vuex actions

From the course: Building Laravel and Vue.js 2 Web Apps

Start my 1-month free trial

Dispatching Vuex actions

- [Instructor] Next we'll talk about Vuex actions while we complete our updates to the Category Manager component. We still need to handle remove category and save categories in the Vuex way. These are not just simple mutations because they involve asynchronous operations on the server and we should really only mutate the state after those are complete. For asynchronous changes instead of committing mutations from our components we'll dispatch actions and then the mutation will be committed from inside an action method. It's actually common to wrap all mutations and actions for consistency and because you may need the flexibility of an action in the future. So let's look at an example. We'll start with save categories. We'll take all of this out and bring it to the store. So in the store I'm going to add an actions object. And the first action I'll add will be save categories. This will take a context object that includes the commit function and the state. It can also accept an…

Contents