父组件

import React,{Component} from 'react';
import SonClick from './SonCllick/SonClick';
class ParentClick extends Component{
MakeMoney(){
alert("我在挣钱!");
}
render(){
return(
<div>

<div>
<SonClick ref="child" onRef={this.onRef} MakeMoney={this.MakeMoney}></SonClick>
</div>
</div>
)
}
}

export default ParentClick;


子组件

import React,{Component} from 'react';

class SonClick extends Component{
StudyMakeMoney=()=>{ // 学习挣钱,调用父组件方法
this.props.MakeMoney();
}
render(){
return(
<div>
我是子组件

<div>
<button onClick={this.StudyMakeMoney}>调用父组件中的方法</button>
</div>
</div>
)
}
}

export default SonClick;


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2021-12-05
猜你喜欢
  • 2022-03-04
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案