DEV Community

Max Walter
Max Walter

Posted on

2 1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay