Answer the question
In order to leave comments, you need to log in
How to correctly bind the v-model of the change event of an input component in Vue?
It works with the input event, but not with the change event.
Here is the component:
<div>
<input
@input="updateValue($event.target.value)"
@change="updateValueChange($event.target.value)"
:value="value"
/>
/>
props: ['value']
methods: {
updateValue(value) {
this.$emit('input', value)
},
updateValueChange(value) {
this.$emit('change', value)
},
}
Answer the question
In order to leave comments, you need to log in
Internally, v-model uses different properties and fires different events for different input elements:
elements for text input and multiline text use the value property and the input event ;
checkboxes and radio buttons use the checked property and the change event;
dropdowns use the value property and the change event.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question