I'm trying to bind user input from a form to a state in my vuex store.
The state looks like this:
customers: [
{firstName: "", lastName: "", age: ""},
{firstName: "", lastName: "", age: ""},
{firstName: "", lastName: "", age: ""}
]
I've tried to use v-model on a computed property that invokes get and set method. I found an explanation here.
This works perfectly for an object, but unfortunately there is no explanation how to use this on an array of objects.
I'm looking for something like this:
computed: {
firstName: {
get () {
return this.$store.state.customers[i].firstName
},
set (value) {
this.$store.commit('changeFirstname', {value, index})
}
}
}
But obviously this didn't work, because I can't pass the index to the computed property. Has anybody a solution for this? Is this a good use case for a deep watcher?
This is my first question, please let me know if I forget something or done something wrong, so that I can improve my asking. Thanks!