react 子组件访问父组件的方法

  1. 回调函数(推荐)
    地址:https://ourcodeworld.com/articles/read/409/how-to-update-parent-state-from-child-component-in-react
  2. 获得父组件的实例(不推荐)
    var parent = this._reactInternalInstance._currentElement._owner._instance;
    地址:https://stackoverflow.com/questions/34257665/is-there-any-way-to-access-the-parent-component-instance-in-react

猜你喜欢

转载自www.cnblogs.com/cag2050/p/9068533.html