FrontendDeveloper.in

Vue.js question detail

How to use model directive with two way computed property?

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
}
}
Back to all Vue.js questions
Get LinkedIn Premium at Rs 399