0 votes
in VueJS by
How to use model directive with two way computed property?

1 Answer

0 votes
by

You can still use model directive using two-way computed property with a setter.

 <input v-model="username">
 computed: {
  username: {
    get () {
      return this.$store.state.user.username
    },
    set (value) {
      this.$store.commit('updateProfile', value)
    }
  }
 }
 mutations: {
       updateProfile (state, username) {
         state.user.username = username
       }
 }

Related questions

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