Skip to content

Grid 宫格布局组件

宫格组件一般用于同时展示多个同类项目的场景,可以给宫格的项目设置徽标组件(badge),或者图标等,也可以扩展为左右滑动的轮播形式。 平台差异

📌平台差异说明

APP(vue)H5微信小程序支付宝小程序

🏯基本使用示例

html
<!-- 全局使用 -->
<hy-gird :list="list"></hy-gird>
ts
import { IconConfig } from "@hy-app/ui";
import { ref } from "vue";

// 创建响应式数据
const list = ref([
  {
    icon: IconConfig.CRY_FILL,
    name: "小狗",
  },
  {
    icon: "https://img1.baidu.com/it/u=563605416,3386931726&fm=253",
    name: "小猫",
  },
  {
    icon: "star",
    name: "小鸡",
  },
]);

设置间距

html
<!-- 全局使用 -->
<hy-gird :list="list" gap="10px"></hy-gird>

设置宫格列数

html
<!-- 全局使用 -->
<hy-gird :list="list" col="5"></hy-gird>

自定义插槽

html
<template>
  <hy-grid :list="list">
    <template #default="{record}">
      <hy-image :src="record.url" width="80" height="80"></hy-image>
      <text>record.title</text>
    </template>
  </hy-grid>
</template>

<script setup="">
  import { IconConfig } from "@hy-app/ui";
  import { ref } from "vue";

  // 创建响应式数据
  const list = ref([
    {
      url: IconConfig.CRY_FILL,
      title: "小狗",
    },
    {
      url: "https://img1.baidu.com/it/u=563605416,3386931726&fm=253",
      title: "小猫",
    },
    {
      url: "star",
      title: "小鸡",
    },
  ]);
</script>

API

Grid Props

参数说明类型默认值
list数据集GridItemVo[]-
col宫格的列数number4
size图标大小,数值默认单位pxnumber|string4
customKeys自定义键值CustomKeysVo{name: 'name',icon: 'icon'}
border是否显示宫格的边框booleanfalse
itemHeight单个宫格高度,数值默认单位pxstring | number100px
align格对齐方式,表现为数量少的时候,靠左,居中,还是靠右center|left|rightleft
gap间隔,数值默认单位pxstring | number0
bgColor宫格的背景颜色stringtransparent
iconProps图标属性api配置,详见图标ApiHyIconProps-
customStyle自定义需要用到的外部样式CSSProperties-
customClass自定义外部类名string-

Events

事件名说明回调参数
click点击宫格触发(item: GridItemVo | string)

Slots

插槽名说明接收值
default默认插槽record: GridItemVo | string

Typings

类型说明
ts
type GridItemVo = {
  /**
   * 图标名称或图片地址
   * */
  icon?: string;
  /**
   * 名称
   * */
  name?: string;
  /**
   * 图标属性api配置
   * */
  iconProps?: Partial<HyIconProps>;
  /**
   * 自定义内容键值对
   * */
  [key: string]: any;
};

type CustomKeysVo = {
  /**
   * 自定义标题键名
   * */
  name: string;
  /**
   * 自定义icon键名
   * */
  icon: string;
};
07:02