react父组件如何调用子组件的方法

父组件

<button onClick={
    
    this.reset}>重置</button>
<Son ref='son' onRef={
    
    this.onRef}></Son>

reset=()=>{
    
    
	this.son.clickReset()
}

onRef=(ref)=>{
    
    
	this.son=ref
}

子组件

componentDidMount=()=>{
    
    
	this.props.onRef(this)
}

clickReset=()=>{
    
    
	alert("重置")
}

猜你喜欢

转载自blog.csdn.net/qq_45785424/article/details/114288388