console
new Vue({
el: '#app',
components: {
'child': {
props: ['myMessage', 'counter'],
template: '<div><p class="message">{{myMessage}} : {{counter}}</p> <input type="button" @click="cadd" value="子组件测试"></div>',
methods: {
cadd() {
this.counter += 1
this.$emit('update:counter', this.counter)
}
}
}
},
data: {
parentMsg: 'Hello Vue.js!',
count: 1
},
methods: {
add() {
return this.count+=1
}
}
})
<script src="https://unpkg.com/vue"></script>
<div id="app">
<input v-model="parentMsg">
<p>计数器:{{count}}</p>
<input type="button" @click="add" value="加 1">
<br>
<child v-bind:my-message="parentMsg" :counter.sync="count"></child>
</div>