Layout 布局

提供了van-rowvan-col两个组件来进行行列布局

使用指南

  1. import { Row, Col } from 'vant';
  2. Vue.use(Row).use(Col);

代码演示

基本用法

Layout 组件提供了24列栅格,通过在Col上添加span属性设置列所占的宽度百分比此外,添加offset属性可以设置列的偏移宽度,计算方式与 span 相同

  1. <van-row>
  2. <van-col span="8">span: 8</van-col>
  3. <van-col span="8">span: 8</van-col>
  4. <van-col span="8">span: 8</van-col>
  5. </van-row>
  6. <van-row>
  7. <van-col span="4">span: 4</van-col>
  8. <van-col span="10" offset="4">offset: 4, span: 10</van-col>
  9. </van-row>
  10. <van-row>
  11. <van-col offset="12" span="12">offset: 12, span: 12</van-col>
  12. </van-row>

设置列元素间距

通过gutter属性可以设置列元素之间的间距,默认间距为 0

  1. <van-row gutter="20">
  2. <van-col span="8">span: 8</van-col>
  3. <van-col span="8">span: 8</van-col>
  4. <van-col span="8">span: 8</van-col>
  5. </van-row>

Flex 布局

type 属性设置为 flex 可以启用 flex 布局,便于进行灵活的对齐

  1. <!-- 左对齐 -->
  2. <van-row type="flex">
  3. <van-col span="6">span: 6</van-col>
  4. <van-col span="6">span: 6</van-col>
  5. <van-col span="6">span: 6</van-col>
  6. </van-row>
  7. <!-- 居中 -->
  8. <van-row type="flex" justify="center">
  9. <van-col span="6">span: 6</van-col>
  10. <van-col span="6">span: 6</van-col>
  11. <van-col span="6">span: 6</van-col>
  12. </van-row>
  13. <!-- 右对齐 -->
  14. <van-row type="flex" justify="end">
  15. <van-col span="6">span: 6</van-col>
  16. <van-col span="6">span: 6</van-col>
  17. <van-col span="6">span: 6</van-col>
  18. </van-row>
  19. <!-- 两端对齐 -->
  20. <van-row type="flex" justify="space-between">
  21. <van-col span="6">span: 6</van-col>
  22. <van-col span="6">span: 6</van-col>
  23. <van-col span="6">span: 6</van-col>
  24. </van-row>
  25. <!-- 每个元素的两侧间隔相等 -->
  26. <van-row type="flex" justify="space-around">
  27. <van-col span="6">span: 6</van-col>
  28. <van-col span="6">span: 6</van-col>
  29. <van-col span="6">span: 6</van-col>
  30. </van-row>

API

Row

参数说明类型默认值版本
type布局方式,可选值为flexString-1.1.9
gutter列元素之间的间距(单位为px)String | Number--
tag自定义元素标签Stringdiv-
justifyFlex 主轴对齐方式,可选值为 end center space-around space-betweenStringstart1.1.9
alignFlex 交叉轴对齐方式,可选值为 center bottomStringtop1.1.9

Col

参数说明类型默认值版本
span列元素宽度String | Number--
offset列元素偏移距离String | Number--
tag自定义元素标签Stringdiv-

原文: https://youzan.github.io/vant/#/zh-CN/col