react-父组件触发子组件的事件
2019-06-12 本文已影响0人
小白修仙路
点击父组件触发子组件的方法
==<ChildDemo onRef = { this.onRef } />
<div onClick={this.Parent}>点击父组件触发子组件click事件</div>
onRef=()=>{
this.child = ref
}
Parent=()=>{
this.child.childFun() //childFun是定义在子组件的事件
}

定义子组件
constructor(props){
super(props)
this.props.onRef(this) //此定义必须写
}
childFun=()=>{
console.log("点击父组件触发子组件")
}
