DEV Community

Max Walter
Max Walter

Posted on

vuejs use v-model within a custom component

You can use the v-model directive to create two-way data bindings on form input, textarea, and select elements. It automatically picks the correct way to update the element based on the input type. Although a bit magical, v-model is essentially syntax sugar for updating data on user input events, plus special care for some edge cases.

<input v-model="myValueVariable" />

But if you want to use v-model within a custom component you will realize that nothing happens.
Thats because there is no event that could trigger a v-model change. The event we are searching for is input.

this.$emit('input', yourValueVariabel)

Top comments (0)