In my Vue 2 project, I make use of vuex.
Currently, I am working on implementing two-way binding for this HTML element:
<input v-model="message">
computed: {
message: {
get () {
return this.$store.state.obj.message
},
set (value) {
this.$store.commit('updateMessage', value)
}
}
}
My aim is to use mappers within the get and set methods for cleaner code:
computed: {
message: {
get () {
return ...mapState("obj", ["message"])
},
set (value) {
...mapMutations("obj/updateMessage", value)
}
}
}
However, I encounter errors on two lines:
return ...mapState("obj", ["message"]) - Expression expected.
...mapMutations("obj/updateMessage", value) - Declaration or statement expected.
Is there a way to successfully use mappers within the get and set methods?
UPDATE: I have already imported mapMutations and mapState to the component.