0 votes
in VueJS by
Can I perform mutations directly in strict mode?

1 Answer

0 votes
by

In strict mode, you can't mutate state directly using v-model attribute. If you use v-model it throws an error because mutation is not performed inside an explicit Vuex mutation handler.

For example, the below input throws an error due to v-model usage

<input v-model="stateObject.message">

In this case, you need to bind the 's value. It can be resolved using value attribute as below,

<input :value="username" @input="updateProfile">

computed: {
  ...mapState({
    username: state => state.user.username
  })
},
methods: {
  updateProfile (e) {
    this.$store.commit('updateProfile', e.target.value)
  }
},
mutations: {
  updateProfile (state, username) {
    state.user.username = username
  }
}

Related questions

0 votes
asked Sep 9, 2023 in VueJS by DavidAnderson
0 votes
asked Sep 7, 2023 in VueJS by DavidAnderson
...