# Grid 宫格
宫格可以在水平方向上把页面分隔成等宽度的区块,用于展示内容或进行页面导航。
# 引入
import PressGrid from 'press-ui/press-grid/press-grid.vue';
import PressGridItem from 'press-ui/press-grid-item/press-grid-item.vue';
export default {
components: {
PressGrid,
PressGridItem,
}
}
# 代码演示
# 基本用法
通过icon属性设置格子内的图标,text属性设置文字内容。
<press-grid>
<press-grid-item icon="photo-o" text="文字" />
<press-grid-item icon="photo-o" text="文字" />
<press-grid-item icon="photo-o" text="文字" />
<press-grid-item icon="photo-o" text="文字" />
</press-grid>
# 自定义列数
默认一行展示四个格子,可以通过column-num自定义列数。
<press-grid :column-num="3">
<press-grid-item
icon="photo-o"
text="文字"
v-for="(item,index) of 6"
:key="index"
/>
</press-grid>
# 自定义内容
通过插槽可以自定义格子展示的内容。
<press-grid :column-num="3" :border="false">
<press-grid-item
use-slot
v-for="(item,index) of 3"
:key="index"
>
<img
style="width: 100%; height: 90px;"
:src="imageList[index]"
/>
</press-grid-item>
</press-grid>
# 正方形格子
设置square属性后,格子的高度会和宽度保持一致。
<press-grid square>
<press-grid-item icon="photo-o" text="文字" v-for="(item,index) of 8" :key="index" />
</press-grid>
# 格子间距
通过gutter属性设置格子之间的距离。
<press-grid :gutter="10">
<press-grid-item icon="photo-o" text="文字" v-for="(item,index) of 8" :key="index" />
</press-grid>
# 内容横排
将direction属性设置为horizontal,可以让宫格的内容呈横向排列。
<press-grid direction="horizontal" :column-num="2">
<press-grid-item icon="photo-o" text="文字" />
<press-grid-item icon="photo-o" text="文字" />
<press-grid-item icon="photo-o" text="文字" />
</press-grid>
# 页面跳转
可以通过url属性进行页面跳转,通过link-type属性控制跳转类型。
<press-grid clickable :column-num="2">
<press-grid-item
icon="home-o"
link-type="navigateTo"
url="/pages/index/index"
text="Navigate 跳转"
/>
<press-grid-item
icon="search"
link-type="reLaunch"
url="/pages/index/index"
text="ReLaunch 跳转"
/>
</press-grid>
# 提示信息
设置dot属性后,会在图标右上角展示一个小红点。设置badge属性后,会在图标右上角展示相应的徽标。
<press-grid :column-num="2">
<press-grid-item icon="home-o" text="文字" dot />
<press-grid-item icon="search" text="文字" badge="99+" />
</press-grid>
# API
# Grid Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| column-num | 列数 | number | 4 |
| icon-size | 图标大小,默认单位为px | string | 28px |
| gutter | 格子之间的间距,默认单位为px | string | number | 0 |
| border | 是否显示边框 | boolean | true |
| center | 是否将格子内容居中显示 | boolean | true |
| square | 是否将格子固定为正方形 | boolean | false |
| clickable | 是否开启格子点击反馈 | boolean | false |
| direction | 格子内容排列的方向,可选值为 horizontal | string | vertical |
reverse v1.7.0 | 是否调换图标和文本的位置 | boolean | false |
| use-slot | 是否使用自定义内容的插槽 | boolean | false |
# GridItem Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| text | 文字 | string | - |
| icon | 图标名称或图片链接,可选值见 Icon 组件 | string | - |
| icon-color | 图标颜色 | string | - |
| icon-prefix | 第三方图标前缀 | string | press-icon |
| dot | 是否显示图标右上角小红点 | boolean | false |
| badge | 图标右上角徽标的内容 | string | number | - |
| url | 点击后跳转的链接地址 | string | - |
| link-type | 链接跳转类型,可选值为 redirectTo switchTab reLaunch | string | navigateTo |
# GridItem Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| click | 点击格子时触发 | - |
# GridItem Slots
| 名称 | 说明 |
|---|---|
| - | 自定义宫格的所有内容,需要设置use-slot属性 |
| icon | 自定义图标,如果设置了use-slot或者icon属性则不生效 |
| text | 自定义文字,如果设置了use-slot或者text属性则不生效 |