父?jìng)髯樱和ㄟ^(guò)在子組件標(biāo)簽中傳值,子組件通過(guò)props進(jìn)行接收。
子傳父:通過(guò)事件,$emit(父組件方法,數(shù)據(jù)),父組件進(jìn)行接收。

image.png
父組件
<template>
<div>
<子組件 :子組件props=父組件數(shù)據(jù) @子組件發(fā)射的方法=父組件接收></子組件>
</div>
</template>
<script>
import 子組件 from '子組件路徑'
export default {
data () {
父組件數(shù)據(jù) :數(shù)據(jù)
},
componets : {
子組件
},
methods : {
父組件接收(數(shù)據(jù)) {
方法體
}
}
}
</script>
子組件
<template>
<div>
<p>{{子組件props}}</p>
<button @click="子組件發(fā)射方法">發(fā)射</button>
</div>
</template>
<script>
export default {
props : {
子組件props
},
methods : {
子組件發(fā)射方法 () {
方法體
this.$emit('子組件發(fā)射方法',數(shù)據(jù))
}
}
}
</script>