表单样式

三等分

import React from "react";
import { Input, Form, Row, Col, Button } from "antd";

const formItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 8 }
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 16 }
  }
};

const formLargeItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 4 }
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 20 }
  }
};

class FormLayout extends React.PureComponent {
  static defaultProps = {
    onSubmit() {}
  };

  handleSubmit = e => {
    e.preventDefault();

    const { form, onSubmit } = this.props;
    const { validateFields, validateFieldsAndScroll } = form;
    validateFields((error, values) => {
      if (!error) {
        onSubmit(values);
      }
    });

    validateFieldsAndScroll((error, values) => {
      if (!error) {
        onSubmit(values);
      }
    });
  };

  render() {
    const { form } = this.props;
    const { getFieldDecorator } = form;
    return (
      <Form {...formItemLayout} onSubmit={this.handleSubmit}>
        <Row gutter={24}>
          <Col span={8}>
            <Form.Item label="用户名">
              {getFieldDecorator("username")(<Input />)}
            </Form.Item>
          </Col>
          <Col span={16}>
            <Form.Item {...formLargeItemLayout} label="密码">
              {getFieldDecorator("password")(<Input type="password" />)}
            </Form.Item>
          </Col>
          <Col offset={8} span={16}>
            <Form.Item colon={false} label=" ">
              <Button type="primary" htmlType="submit">
                Submit
              </Button>
            </Form.Item>
          </Col>
        </Row>
      </Form>
    );
  }
}

export default Form.create()(FormLayout);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
上次更新: 11/5/2019, 6:30:17 AM