使用Form.setFieldsValue方法将初始值为另一个值的表单项更新为最终显示值。
示例代码:
import React, { useState } from 'react';
import { Form, Input, Button } from 'antd';
const DemoForm = () => {
const [form] = Form.useForm();
const [inputValue, setInputValue] = useState('初始值');
const handleSubmit = (values) => {
console.log('表单提交的值', values);
};
const handleInputChange = (e) => {
setInputValue(e.target.value);
};
const handleSetFieldsValue = () => {
form.setFieldsValue({
testInput: inputValue,
});
};
return (
);
};
export default DemoForm;
上一篇:Antd表单无法识别输入值”
下一篇:antd表单中的复选框字段未重置