v-model is just an abstraction on top of unidirectional data flow. Essentially, your custom child component needs to do two things:
- Accept a prop named
value.
- Emit an event named
input with new data.
So your child component would be used like this:
<child-component :value="myVal" @input="myVal = $event"></child-component>
In the above code, $event is a special template construct that holds the data which child component has emitted as part of the event payload. The @input event is simply updating myVal value which will again be passed to a child component via :value binding and thus one-way data flow.
Now, this pattern is repeated so many times that Vue.js has provided a simple v-model syntax-sugar which can be used instead of the above code.
<child-component v-model="myVal"></child-component>
Also, if for some reason, you don't want to use value or input as your prop and event, then you can change them using model attribute. Here is the additional documentation for this.
Note that, if you are using Redux/Vuex, then avoid using v-model. For nested data, there is a good chance that you will land up in edge-case scenarios.