使用Ant Design Form表单验证遇到一个坑

80 阅读1分钟

问题描述

在用蚂蚁 Ant Design 表单验证的时候在render 函数中按照文档来引入

const { getFieldDecorator } = this.props.form;

结果总是给我报TypeError: Cannot read property 'getFieldDecorator' of undefined 这么一个错误,看官网上面也没对这个有明确的说明,问题解决之后记录一下,以便自己牢记不会放第二次错误 解决方式如下: 需要调用Form中的create方法 在组件的最后这么写

const WrappedFormComponent = Form.create()(FormComponent);

export default WrappedFormComponent;

其中 FormComponent 是你命名组件的名称,WrappedFormComponent组件是使用Form.create()方法之后暴露出去的组件。 如此,问题解决...