赞
踩
const [form] = Form.useForm()
const requestProfileList = useCallback(async () => {
try {
const { result } = await fetchProfileListRequest()
form.setFieldsValue(result)
} catch (e) {
message.error(e)
}
}, [])
在Form.item中只要把name属性确定好就OK
<Form layout="horizontal" onFinish={handleOnFinish} form={form}>
</Form>
const handleOnFinish = useCallback(
(value) => {
//拿到数据
console.log(value)
},
[]
)
import { FormComponentProps } from 'antd/lib/form';
//定义form 数据
export interface FormData {
name: string;
account: string;
number: string;
}
interface ComponentProps extends FormComponentProps {
onSubmit(value?: FormData): void;
}
const FilterForm: FC<ComponentProps> = ({ form, onSubmit }) => {
}
const { getFieldDecorator, setFieldsValue } = form;
<Form.Item label={'姓名'}>
{getFieldDecorator('name')(
<Input
prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
style={{ width: 145 }}
placeholder="请输入员工姓名"
/>,
)}
</Form.Item>
<Form.Item label={'姓名'}>
{getFieldDecorator('name', {
initialValue: '张三',
})(
<Input
prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
style={{ width: 145 }}
placeholder="请输入员工姓名"
/>,
)}
</Form.Item>
//提交表单
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e): void => {
e.preventDefault();
form.validateFields((err, values) => {
if (!err && onSubmit) {
//通过onSubmit传递给父组件
onSubmit(values);
}
});
};
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。