react父组件获取子组件的值或方法

父组件:

  <Child onRef={(ref) => { this.child = ref; }} />

  用的时候直接从this.child里面取

子组件:

  componentDidMount() {
      this.props.onRef(this);
     }
posted @ 2019-12-10 17:22  浪浪浪浪浪浪浪浪  阅读(7181)  评论(3编辑  收藏  举报