react antd form.item 类式组件如何使用getFieldDecorator

<Form.Item>

            {
              getFieldDecorator('agreement', {
                valuePropName: 'checked',
              })(<Checkbox> 设为默认</Checkbox>)
            }

          </Form.Item>

使用类式组件 会报错 'getFieldDecorator' is not defined

查了些资料 const {getFieldDecorator} = this.props.form; 这个写在return上也报错

Contacts = Form.create({})(Contacts); 报的错好像是版本不对

阅读 2.8k
1 个回答

在antd v4.x版本中,已移除Form.create() ,表单现在有它自己的数据范围,你不再需要getFieldDecorator了。直接使用Form.Item 即可。
官方demo

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题