通过子组件触发事件
父组件通过props属性传递一个函数给子组件,当触发事件的时候,调用该函数,将值作为参数传递过去
//父组件
<TestA tilte = {() => this.getForm(params)}>
//子组件
static propTypes = {
title: PropTypes.func
}
change = () => {
this.props.title(data);
}
通过父组件触发事件
子组件定义一个函数,父组件通过ref调用子组件定义方法来获取值
//父组件
pw = createRef()
<addForm ref = {this.pw} />
this.pw.current.getForm()
//子组件
getForm = () => {
return this.formRef.current;
}
async
async 返回promise,值为async函数中返回的值