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.

Handling form input with Vuex

Handling form input with Vuex

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

Start my 1-month free trial

Handling form input with Vuex

- [Narrator] Now we'll take a look at how form input is handled when we're using Vuex. So in our category manager, these v-model bindings will still actually work if strict, which is a store option, is not set to true. But, we don't want to be mutating the state directly with two-way binding because it makes it harder to trace and reason about our application, and it's not in the spirit of Vuex. Instead, we want to do one-way binding of the value from the state with :value. And then, on input, we'll have to commit a mutation to change the value in the store. So, we could say, as a first attempt that we'll create an updateName method, which will create a mutation to update the name, we'll pass in the event so that we can pass the new name, and will also need the index of the category item to update. But, instead of a seperate method for updating each category attribute, which could get tedious, how about a generic method for updating any attribute. So we can just call it update, we'll…

Contents