Skip to content

Instantly share code, notes, and snippets.

@8bu
Created January 23, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 8bu/27745edc98c260a067376b8917e9586a to your computer and use it in GitHub Desktop.
Save 8bu/27745edc98c260a067376b8917e9586a to your computer and use it in GitHub Desktop.
V-model Custom Component usage
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