S
S
Sergey Semenov2020-10-21 18:02:23
Vue.js
Sergey Semenov, 2020-10-21 18:02:23

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

1 answer(s)
C
coderisimo, 2020-10-21
@Skaper777


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 question

Ask a Question

731 491 924 answers to any question