父组件:
//导入子组件
import PartList from "./PartList.js"
//获取子组件
onRef = (ref) => {
this.partList = ref
}
调用子组件得方法:
componentDidMount() {
this.partList.alertText();
}
//render
render(){
return(
<div>
//载入子组件
<PartList onRef={this.onRef} />
</div>
)
}
子组件:
alertText=()={
alert("我是子组件的方法");
}