In the docs, it is said that:
<input v-model="searchText" />
// becomes
<input
:value="searchText"
@input="searchText = $event.target.value"
/>
but
<CustomInput v-model="searchText" />
// becomes
<CustomInput
:model-value="searchText"
@update:model-value="newValue => searchText = newValue"
/>
Note the :model-value
/modelValue
props. Why doesn't custom input props become :value
, just like the native one? Like this:
<CustomInput v-model="searchText" />
// becomes
<CustomInput
:value="searchText"
@input="newValue => searchText = newValue"
/>
@input
on custom components it would be impossible to bind this event to the real<input>
used in a component.v-model
could handle multiple props:v-model.prop2
- some other prop could be bound too.@input="newValue => searchText = newValue"
- you can't do that sincenewValue
is an event, not a new value.v-model
on native inputs is a good abstraction to avoid bothering about which exact native event we need for value changes.