首页 > 其他 > 详细

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

时间:2020-02-23 21:39:36      阅读:76      评论:0      收藏:0      [点我收藏+]
class Parent extends Component {
  handleSth () {
    console.log(‘触发父组件成功‘)
  }
  render () {
    return (
      <div>
        <Child childHandleSth={this.handleSth}></Child>
      </div>
    )
  }
}

export default Parent
class Child extends Component {
  constructor (props) {
    super(props)
    this.state = {}
  }
  render () {
    return (
      <div onClick={() => this.props.childHandleSth()}>子组件</div>
    )
  }
}
export default Child

 

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

原文:https://www.cnblogs.com/pcxhahaha/p/12354106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!