# t-grid-item
GridItem 宫格项
t-grid-item 组件介绍
t-grid-item 是宫格组件的子组件,用于定义单个宫格项的内容,支持图标、文字、徽标等配置。
t-grid-item 平台兼容
| Harmony | H5 | Android | iOS | 小程序 | UTS |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
t-grid-item 基础用法
基础用法参考 demo/grid/grid.uvue,作为 t-grid 的子组件使用。
vue
<template>
<view class="p-15">
<tui-theme-switch></tui-theme-switch>
<t-card class="mb-15"
title="Grid 宫格组件"
sub-title="宫格组件以灵活的栅格系统为核心,通过配置列数和可选边框,以及自定义子项样式,实现整齐划一的布局,为内容展示提供清晰有序的视觉体验。">
</t-card>
<t-section title="基础功能"
class="mb-15">
</t-section>
<t-grid :column="5"
class="r-10 mb-15">
<t-grid-item v-for="i in 5"
:key="i"
:icon="`/static/grid/grid (${i}).png`"
:label="`功能${i}`">
</t-grid-item>
</t-grid>
<t-section title="主题+徽标+图标"
class="mb-15">
</t-section>
<t-grid :column="5"
class="r-10 mb-15 s-75"
type="success"
size="medium"
child-label-class="mt-0">
<!-- 通过插槽方式显示徽标 -->
<t-grid-item icon="red-packet"
label="待付款">
<template #badge>
<t-badge type="error"
class="da dr-5 dt-7"
text="56556">
</t-badge>
</template>
</t-grid-item>
<!-- 通过属性配置显示徽标 -->
<t-grid-item icon="car"
label="待发货"
:badge="true"
:badge-attrs="{text:'99',class:'da dr-5 dt-7', type:'error'}">
</t-grid-item>
<t-grid-item icon="bag"
label="待收货"
:badge="true"
:badge-attrs="{text:'HOT',class:'da dr-5 dt-7', type:'error'}">
</t-grid-item>
<t-grid-item icon="chat"
label="待评价">
</t-grid-item>
<t-grid-item icon="integral"
label="退货">
</t-grid-item>
</t-grid>
<t-section title="列数设置+徽标"
class="mb-15"></t-section>
<t-grid :column="2"
type='primary'
class="r-10 mb-15"
child-label-class="mt-0">
<t-grid-item icon="calendar"
label="签到"></t-grid-item>
<t-grid-item icon="gift"
label="积分">
<template #badge>
<t-badge type="primary"
class="da dr-55 dt-15"
text="15">
</t-badge>
</template>
</t-grid-item>
</t-grid>
<t-section title="列数设置"
class="mb-15">
</t-section>
<t-grid :column="4"
class="r-10 mb-15">
<t-grid-item v-for="i in 5"
:key="i"
:icon="`/static/grid/grid (${i}).png`"
:label="`功能${i}`"
type="error">
</t-grid-item>
</t-grid>
<t-section title="可滚动"
class="mb-15">
</t-section>
<swiper :indicator-dots="true"
:autoplay="true"
:interval="3000"
:duration="1000"
class="h-200">
<swiper-item>
<t-grid :column="4">
<t-grid-item v-for="i in 8"
:key="i"
:icon="`/static/grid/grid (${i}).png`"
:label="`功能${i}`">
</t-grid-item>
</t-grid>
</swiper-item>
<swiper-item>
<t-grid :column="4">
<t-grid-item v-for="i in 8"
:key="i"
:icon="`/static/grid/grid (${i}).png`"
:label="`功能${i}`">
</t-grid-item>
</t-grid>
</swiper-item>
</swiper>
</view>
</template>
<script setup>
import { ref } from 'vue'
const column = ref(5)
</script>t-grid-item Props
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
path | 点击组件后跳转的页面路径;为空时仅响应事件 | string | '' |
hover | 是否启用点击效果 | boolean | true |
type | 组件主题类型,可选 info、primary、error、warning、success | string | '' |
disabled | 是否禁用 | boolean | false |
effect | 组件显示主题,可选 normal、dark、light、plain | string | 'normal' |
size | 组件尺寸,可选 large、medium、small、mini | string | 'medium' |
icon | 图标名称或图片地址 | string | 'photo' |
iconClass | 图标样式 | string | '' |
label | 显示文本 | string | '' |
labelClass | 显示文本样式 | string | '' |
badge | 是否显示徽标 | boolean | true |
badgeAttrs | 徽标的属性配置,支持 t-badge 组件的所有属性 | UTSJSONObject | {} |
t-grid-item Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
click | 点击时触发 | - |
transitionend | 动画结束时触发 | - |
initFinished | 组件初始化完成时触发,返回组件节点信息 | - |
touchstart | 触摸开始时触发 | - |
touchend | 触摸结束时触发 | - |
touchmove | 触摸移动时触发 | - |
touchcancel | 触摸取消时触发 | - |
t-grid-item Slots
| 插槽名 | 说明 |
|---|---|
default | 默认插槽,可自定义宫格项内容 |
badge | 徽标插槽,可自定义徽标内容 |