antd获取/更改form表单数据(表单域数据)

创建ref引用

formRef = React.createRef();

表单和ref绑定

//ref={this.formRef}  先给Form 
<Form ref={this.formRef} name="control-ref" onFinish={this.onFinish}>
   <Form.Item name="name" label="Name" rules={[{ required: true }]}>
        <Input />
   </Form.Item>
   <Form.Item name="age" label="Age" rules={[{ required: true }]}>
        <Input />
    </Form.Item>
</Form>

获取值

var name = this.taskDetailsExportRef.current.getFieldValue('name');
var age = this.taskDetailsExportRef.current.getFieldValue('age');

更改

this.formRef.current.setFieldsValue({
	name: 'name change',
	age: 'age change'
});

你可能感兴趣的:(前端综合,前端,javascript,开发语言)