Parent父组件和Children都是类组件,Parent引入Children后不渲染,只是想要获取Children的ref或者里面的一个方法,怎么实现
类式组件的话,你在引入 Children 组件的时候 传递一个函数过去,如: ,然后在子组件 componentDidMount 生命周期中 this.props.onRef(this)然后在 父组件声明这个函数onRef= (ref) => {console.log(ref) // 此处ref指向 Children 类}