Created
January 23, 2019 09:33
-
-
Save 8bu/27745edc98c260a067376b8917e9586a to your computer and use it in GitHub Desktop.
V-model Custom Component usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v-model uses the @input event by default, so if you want to use v-model on a custom component you need to emit the input event to the parent. So, in your component, you simply do: | |
<input class="product_name form-control" @input="$emit('input', $event.target.value)" /> | |
Now in your parent you can do: | |
<products-list v-model="product.name"></products-list> | |
You can see the full example on this JSFiddle: https://jsfiddle.net/7s2ugt11/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment