Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Forked from AndreKR/model_vs_sync.md
Created January 31, 2021 17:27
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 xgenvn/9d9533d10eaa2b3926356d84473211db to your computer and use it in GitHub Desktop.
Save xgenvn/9d9533d10eaa2b3926356d84473211db 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