Layout栅格布局
引入
在app.json或index.json中引入组件,默认为ES6版本
"usingComponents": {
"vtu-layout-row": "/miniprogram_npm/vtuweapp/layout/row/vtu-layout-row",
"vtu-layout-col": "/miniprogram_npm/vtuweapp/layout/col/vtu-layout-col"
}
代码演示
基础布局
Layout 组件提供了12列栅格,通过在Col上添加span属性设置列所占的宽度百分比 此外,添加offset属性可以设置列的偏移宽度,计算方式与 span 相同
<vtu-layout-row>
<vtu-layout-col span="12"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row>
<vtu-layout-col span="6"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="6"><view class="layoutSpan light"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row>
<vtu-layout-col span="4"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="4"><view class="layoutSpan light"></view></vtu-layout-col>
<vtu-layout-col span="4"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan light"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan light"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row>
<vtu-layout-col span="2"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="2"><view class="layoutSpan light"></view></vtu-layout-col>
<vtu-layout-col span="2"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="2"><view class="layoutSpan light"></view></vtu-layout-col>
<vtu-layout-col span="2"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="2"><view class="layoutSpan light"></view></vtu-layout-col>
</vtu-layout-row>
分栏间隔
通过gutter
属性可以设置列元素之间的间距,默认间距为 0
<vtu-layout-row gutter="20">
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan light"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan light"></view></vtu-layout-col>
</vtu-layout-row>
混合布局
<vtu-layout-row gutter="10">
<vtu-layout-col span="8"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="4"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row gutter="10">
<vtu-layout-col span="4"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="2"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row gutter="10">
<vtu-layout-col span="2"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="5"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="5"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
对齐方式
通过align
属性,可将分栏进行灵活的对齐,对齐方式有三种:left
center
right
<vtu-layout-row align="right">
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row align="center">
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row align="left">
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="3"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
分栏偏移
支持偏移指定的栏数。
<vtu-layout-row gutter="20">
<vtu-layout-col span="4"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="4" offset="4"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row gutter="20">
<vtu-layout-col span="2"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="4" offset="2"><view class="layoutSpan"></view></vtu-layout-col>
<vtu-layout-col span="2" offset="2"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
<vtu-layout-row gutter="20">
<vtu-layout-col span="6" offset="2"><view class="layoutSpan"></view></vtu-layout-col>
</vtu-layout-row>
组件参数
Row Props
参数 | 说明 | 类型 | 默认值 | 必填 |
---|
gutter | 列元素之间的间距(单位为px) | Number | 0 | 否 |
align | 水平排列方式 | String | left | 否 |
Col Props
参数 | 说明 | 类型 | 默认值 | 必填 |
---|
span | 栅格占据的列数 | Number | 12 | 否 |
offset | 栅格左侧的间隔格数 | Number | 0 | 否 |
外部样式类
外部样式类名 | 说明 |
---|
v-class | 组件外部样式类 |