我无法使用 "this.props.form"

I can not use "this.props.form"

抱歉,我是 React 的初学者。 如果我弄错了任何单词或想法,请理解。

我用 VS2017 React 模板做了一个项目。 并从 npm 添加 antd。 我正在测试 antd 表单,但我看到了错误。 "(TS) 'Readonly<{ children?: ReactNode; }> & Readonly>' 找不到 'form' 属性。"

我的来源是

import { RounteComponentProps } from 'react-router';
....
export class Test extends React.Component<RouteComponentProps<{}>, {}> {
    ....

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFields(.....);
    }
    ....
}

引用自ant-design document

If the form has been decorated by Form.create then it has this.props.form property.

因此,您需要在组件中添加 Form.create,如下所示:

class CustomizedForm extends React.Component {}

CustomizedForm = Form.create({})(CustomizedForm);