// antd v3
function Demo (props)(
  const { form } = props
  const { getFieldDecorator, getFieldsValue, setFieldsValue } = form
  return (
     <Form>
      <Form.Item>
        {getFieldDecorator('username', {
          rules: [{ required: true }],
        })(<Input />)}
      </Form.Item>
    </Form>
  )
); export default Form.create()(Demo);

 

// antd v4
function Demo (props)(
  const [form] = Form.useForm()
  const { getFieldDecorator, getFieldsValue, setFieldsValue } = form

  retunr (
    <Form>
      <Form.Item name="username" label="usesrname" rules={[{required: true}]}>
        <Input/>
      </Form.Item>
    </Form>
  )

);
 
export default Demo;

  antd4.x移除了 Form.create(),原本的 onFieldsChange 等方法移入 Form 中,通过 fields 对 Form 进行控制

相关文章:

  • 2022-12-23
  • 2021-07-11
  • 2021-09-08
  • 2021-07-28
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2021-07-03
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案