通过父组件给子组件传递函数类型的props实现:子给父传递数据
父组件
定义的组件
<School :getSchoolName="getSchoolName"></School>
methods: {
getSchoolName(name) {
console.log("学校名", name);
}
}
子组件
<button @click="sendSchoolName">把学校名字给app</button>
props: ["getSchoolName"],
methods: {
sendSchoolName() {
this.getSchoolName(this.name);
},
},