# Grid 宫格

概述

Grid 宫格,主要使用场景如:热门内容等。
Grid 提供了fui-grid 和 fui-grid-item 两个组件来进行布局。

# 支持平台

App-vue App-Nvue 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序 H5 PC 快手小程序 钉钉小程序

# 引入

以下介绍两种常用的引入方式。
第一种:在页面中引用、注册
import fuiGrid from "@/components/firstui/fui-grid/fui-grid.vue"
import fuiGridItem from "@/components/firstui/fui-grid-item/fui-grid-item.vue"
export default {
	components:{
		fuiGrid,
		fuiGridItem
	}
}
1
2
3
4
5
6
7
8
第二种:easycom组件规范
传统vue组件,需要安装、引用、注册,三个步骤后才能使用组件。easycom将其精简为一步。

First UI easycom配置请查看 快速上手

如果不了解easycom,可先查看 官网文档 (opens new window)

# 代码演示

部分示例演示,完整使用请参考示例程序以及文档API。
基础使用

九宫格。

<fui-grid>
	<fui-grid-item v-for="(item,index) in 9" :key="index">
		<view class="fui-grid__cell">
			<image src="/static/images/common/icon_tabbar_3x.png" class="fui-icon" mode="widthFix"></image>
			<text>Grid</text>
		</view>
	</fui-grid-item>
</fui-grid>
1
2
3
4
5
6
7
8
高度自适应

通过 square 属性设置宫格item是否为正方形显示,设置为false则高度自适应。

<fui-grid :square="false">
	<fui-grid-item  v-for="(item,index) in 9" :key="index">
		<view class="fui-grid__cell fui-padding">
			<image src="/static/images/common/icon_tabbar_2x.png" class="fui-icon__2x" mode="widthFix">
			</image>
			<text>Grid</text>
		</view>
	</fui-grid-item>
</fui-grid>
1
2
3
4
5
6
7
8
9
修改列数

通过 columns 属性设置宫格每行显示的item数。

<fui-grid :columns="4">
	<fui-grid-item  v-for="(item,index) in 12" :key="index">
		<view class="fui-grid__cell fui-padding">
			<image src="/static/images/common/icon_tabbar_2x.png" class="fui-icon__2x" mode="widthFix">
			</image>
			<text>Grid</text>
		</view>
	</fui-grid-item>
</fui-grid>
1
2
3
4
5
6
7
8
9

# Slots

# fui-grid 组件

插槽名称 说明
default 标签显示内容,内部由一个或多个fui-grid-item组成

# fui-grid-item 组件

插槽名称 说明
default 标签内显示的自定义内容

# Props

# fui-grid 组件

属性名 类型 说明 默认值 平台差异说明
columns Number 每行显示item数 3 -
showBorder Boolean 是否显示边框 true -
borderColor String 边框颜色 #EEEEEE 仅nvue有效,非nvue端通过css变量修改
square Boolean item是否显示为正方形 true -
between V2.0.0+ Boolean item项是否两端对齐,仅在宽度无法拉满且影响美观时使用 false app-vue、h5、微信小程序不支持(无需使用)
emptyElements V2.0.0+ Number, String between为true且数据无法铺满时,末尾补足占位元素个数 false app-vue、h5、微信小程序不支持(无需使用)

TIP

between 为true时,最后一行数据条数 + emptyElements 应等于 columns 值。

# fui-grid-item 组件

属性名 类型 说明 默认值 平台差异说明
highlight Boolean 是否有点击效果 true -
backgroundColor String 背景颜色 transparent -
index Number item索引 0 -

# Events

# fui-grid 组件

事件名 说明 回调参数
@click 点击item时触发 e.detail={
  index:索引
}

# fui-grid-item 组件

事件名 说明 回调参数
@click V1.9.1+ 点击item时触发 e.detail={
  index:索引
}

示例预览

# 示例代码地址

FirstUIGrid 宫格
Last Updated: 1/10/2024, 6:25:05 PM