In most cases, two-way binding is not always suitable. It makes more sense to use one-way binding and explicit data updates in Vuex by binding <input> with the value attribute on the input or change events. You can get this working easily with the following steps:
- Create a method for mutating the state in the mutations property just as you learned in the previous sections:
// vuex-sfc/form-handling/value-event/store/index.js
export default new Vuex.Store({
strict: true,
state: {
message: ''
},
mutations: {
updateMessage (state, message) {
state.message = message
}
}
})
- Bind the <input> element with the value attribute and the input event with the methods, as follows:
// vuex-sfc/form-handling/value-event/components/app.vue
<input v-bind:value="message" v-on:input="updateMessage" />
import { mapState } from 'vuex'
export default {
computed: {
...mapState({
message...