0
votes

maybe i have no luck finding this, but i can't figure it out: i have this field:

<md-input v-if="edit===false" disabled v-model="userdata.username"></md-input>

i am binding the user data in computed with the vuex getter like this:

...mapGetters({
    userdata: "getUserData"
  })

there is no problem, but when i type out in the field, i got an error because it is not recommendable mutate the state outside of mutations, so, how do i update the state using mutations when i type out in the field?

i have this mutation to update the userdata:

[types.UPDATEUSERDATA] (state, user) {
  state.currentUser = user;
}

and this is the getData mutation:

[types.GETUSERDATA] (state) {
  return state.currentUser;
}

thanks in advance.

1

1 Answers

1
votes

sorry, i will leave it here just in case, the answers is in the docs here

just change the v-model to :input and put an avent to update after change like this:

<input :value="message" @input="updateMessage">

so updateMessage is triggered and there is where i mutate the state like this:

updateMessage (e) {
  this.$store.commit('updateMessage', e.target.value)
}