2017-06-21 87 views

回答

1

您可以在给定分配到子组件,然后调用函数形式母象

class Parent extends React.Component { 
    callChildFunction =() => { 
     this.child.handleActionParent(); ///calling a child function here 
    } 
    render(){ 
     return (
      <div> 
      {/* other things */} 
      <Child ref={(cd) => this.child = cd}/> 
      </div> 
    ) 
    } 
} 

class Child extends React.Component { 
    handleActionParent =() => { 
     console.log('called from parent') 
    } 
    render() { 
     return (
      {/*...*/} 
    ) 
    } 
}