父组件
interface initProps ={
}
class ListPage extends Component<initProps>{
child: any = {} //主要加这个
handlePage = (num: number): void => {
// this.child.
console.log(this.child.onChild())
}
onRef = ref => {
this.child = ref
}
render() {
return {
<ListForm onSubmit={this.onSubmit} onRef={this.onRef} />
}
}
}
子组件
import React, { useImperativeHandle } from 'react'
interface ListFormProps {
/** 申请完成触发 */
onRef: any
}
const ListForm: React.FC<ListFormProps> = props => {
const [form] = Form.useForm()
//重置方法
const onReset = () => {
form.resetFields()
}
}
useImperativeHandle(props.onRef, () => ({
// onChild 就是暴露给父组件的方法
onChild: () => {
return form.getFieldsValue()
}
}))