写一个antd的form表单组件
时间: 2023-03-11 19:35:47 浏览: 158
我可以为你提供一个简单的antd表单组件的示例:import { Form, Input, Button } from 'antd';class LoginForm extends React.Component {
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}; render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit}>
<Form.Item>
{getFieldDecorator('username', {
rules: [{ required: true, message: '请输入用户名!' }],
})(
<Input
placeholder="用户名"
/>,
)}
</Form.Item>
<Form.Item>
{getFieldDecorator('password', {
rules: [{ required: true, message: '请输入密码!' }],
})(
<Input
type="password"
placeholder="密码"
/>,
)}
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
登录
</Button>
</Form.Item>
</Form>
);
}
}const WrappedLoginForm = Form.create({ name: 'normal_login' })(LoginForm);export default WrappedLoginForm;
阅读全文