Skip to content
Advertisement

Vue3 use v-model in Child Components

I just found out that in Vue3, v-model is not working responsively / reactively with child Component.

This code will update the username data

JavaScript

If I type something in the input, the username data will change too.

But, when I use Component like this example:

JavaScript

Then I updated my code to use the Component.

Note: The Component is registered successfully.

JavaScript

When I type something, the username data not updated, different with the previous one.

Is there any solution or at least reference of what I’m trying to achieve?

Advertisement

Answer

You can’t expect v-model to implicitly update the underlying element for you. In other words, you’ll still need to handle that within the component itself and expose modelValue as a prop for this to really work. Something like that:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement