Row, Col 配置文档
https://3x.ant.design/components/grid-cn/#components-grid-demo-responsive-more

Row 基本用法

  1. //
  2. <Row gutter={16}>
  3. <Col span={8}></Col>
  4. <Col span={16}></Col>
  5. </Row>
  6. //

响应式用法

image.png

Row, Col的响应式写法

  1. const gutter = { xs: 8, md: 16, xxl: 24 };
  2. const gutter [16, 16];
  3. const gutter = 24;
  4. const col = {
  5. xs: 12,
  6. md: 8,
  7. xxl: 6,
  8. };
  9. <Row gutter={gutter}>
  10. <Col {...col}></Col>
  11. <Col span={16}></Col>
  12. </Row>

style自定义列宽

当 Row, Col需要自适应时,可以用 style来修改列宽

  1. const itemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 18 } };
  2. const fileLayout = {
  3. labelCol: { span: 3, style: { width: '12.3%' } },
  4. wrapperCol: { span: 21, style: { width: '87.7%' } },
  5. };
  6. function App() {
  7. return (
  8. <Row gutter={16}>
  9. <Col span={8}>
  10. <Item label='名称'>
  11. {getFieldDecorator('name', {
  12. initialValue: value.name,
  13. rules: [{ required: true, message: '请输入名称' }],
  14. })(<Input allowClear placeholder='请输入名称' />)}
  15. </Item>
  16. </Col>
  17. <Col span={16}>
  18. <Form.Item label='描述' {...fileLayout}>
  19. {getFieldDecorator('desc', {
  20. initialValue: value.desc,
  21. rules: [{ required: true, message: '请输入描述' }],
  22. })(<Input allowClear placeholder='请输入描述' />)}
  23. </Form.Item>
  24. </Col>
  25. </Row>
  26. );
  27. }

image.png

Row-Col浮动引起的错位

错位问题,大部分是表单验证错误时,布局被撑开,导致流式布局错位,引起的;
解决,Row 添加 type=’flex’
image.png

  1. import { Row, Col } from 'antd';
  2. <Row gutter={16} type="flex">
  3. <Col span={8}>
  4. <Form.Item label='名称'>
  5. {getFieldDecorator('name', {
  6. initialValue: '',
  7. rules: [{ required: true, message: '请输入名称' }],
  8. })(<Input placeholder='请输入名称' allowClear />)}
  9. </Form.Item>
  10. </Col>
  11. <Col span={8}>
  12. <Form.Item label='信息来源'>
  13. {getFieldDecorator('from', {
  14. initialValue: '',
  15. rules: [{ required: true, message: '请选择信息来源' }],
  16. })(
  17. <Select placeholder='请选择信息来源' />,
  18. )}
  19. </Form.Item>
  20. </Col>
  21. </Row>

解决后的,表单展示
image.png