While v-model
is a powerful asset for adding two-way data-binding to vanilla components, it’s not always readily apparent how to add support for v-model
to your own custom components. Turns out though, it’s pretty simple.
All your component needs to do to be compatible with v-model is accept a :value
property and emit an @input
event when the user changes the value.
Examples below.
Source/Copyright: https://alligator.io/vuejs/add-v-model-support/