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

父组件:

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

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

子组件:

  componentDidMount() {
      this.props.onRef(this);
     }

猜你喜欢

转载自www.cnblogs.com/hamili/p/12017962.html
今日推荐