父:
<template>
<div class="home">
<p>父: {{num}}</p>
<MChild v-model="num"></MChild>
</div>
</template>
<script>
import MChild from "../components/MChild/index.vue"
export default {
name: 'home',
data() {
return {
num: 1
}
},
components: {
MChild
}
}
</script>
子:
<template>
<div class="child">
<p>子: {{num}}</p>
<a href="javascript:;" @click="handleAdd">点击+1</a>
</div>
</template>
<script>
export default {
props: {
num: Number
},
model: {
prop: 'num',
event: 'add'
},
methods: {
handleAdd() {
this.$emit('add', ++this.num);
}
}
}
</script>