Skip to content

Instantly share code, notes, and snippets.

@AndreKR
Created August 24, 2017 06:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AndreKR/80953c53bdd1b3a8dfe0f6f6f29a6020 to your computer and use it in GitHub Desktop.
Save AndreKR/80953c53bdd1b3a8dfe0f6f6f29a6020 to your computer and use it in GitHub Desktop.
Vue.js v-model vs. v-bind.sync

Vue.js: v-model vs. v-bind:<propname>.sync

These examples use the expression foo as the data source in the parent.

Prop name Event name
v-model="foo" value by default input by default
v-bind:<propname>.sync="foo" arbitrary update:<propname>

v-model

<comp v-model="foo"></comp><comp :value="foo" @input="v => foo = v"></comp>

this.$emit('input', new_value)

v-bind.sync

<comp :bar.sync="foo"></comp><comp :bar="foo" @update:bar="v => foo = v"></comp>

this.$emit('update:bar', new_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment