父子组件之间不能直接传参或者调用方法
父 => 子,传值(props)
使用v-bind传值给子组件,子组件使用props来接收
父:
子:
子 => 父,传值(
e
m
i
t
)
在
子
组
件
方
法
里
使
用
emit) 在子组件方法里使用
emit)在子组件方法里使用emit来触发父组件的口令绑定的方法
注意html不区分大小写,按理说子组件中声明的口令hideCoupon在父组件绑定在html上时可以用hide-coupon的,但是没触发
父:
子:
子 => 父,调用(
r
e
f
s
)
父
组
件
需
要
定
义
一
个
方
法
,
然
后
在
里
面
通
过
refs) 父组件需要定义一个方法,然后在里面通过
refs)父组件需要定义一个方法,然后在里面通过refs来调用对应子组件的方法
父:
子:
父=>子,调用(provide/inject)
使用provide传递当前组件实例
provide() {
return {
showServiceInfo: this.showServiceInfo
}
},
在后代组件中接收组件
export default {
inject: ["showServiceInfo"],
data() {
return {
serviceList: [],
dialogVisible: false,
multipleSelection: []
}
},
}