.sync vs v-model
HTML
<div id="app">
<h4>Separated value binding + event listening</h4>
<my-comp
v-bind:prop1="buttonLabel1"
V-on:update:prop1="buttonLabel1 = $event">
</my-comp>
<h4>.sync Shorthand</h4>
<my-comp
v-bind:prop1.sync="buttonLabel2">
</my-comp>
<h4>v-model Shorthand</h4>
<my-comp
v-model="buttonLabel3">
</my-comp>
</div>
Vue
Vue.component('my-comp', {
model: {
prop: 'prop1',
event: 'update:prop1'
},
data: function () {
return {
inputValue: ''
}
},
props: ['prop1'],
template: `
<span>
<input type="text"
v-model:value="inputValue">
<button
v-on:click="$emit('update:prop1', inputValue)">
{{prop1}}
</button>
</span>
`
});
new Vue({
el: "#app",
data: {
buttonLabel1: 'Button 1',
buttonLabel2: 'Button 2',
buttonLabel3: 'Button 3',
}
});