翻譯進行中
本頁尚未翻譯為繁體中文,以下顯示簡體中文原文。範例的預設元件文字仍使用繁體中文。
AvatarGroup 头像组
展示头像集合或插槽子项,按 max 显示余量。
引入
uni-app 配置 easycom 后使用 <hui-avatar-group>。公开类型和函数从 @nscode/handy-uni 导入;普通 Vue 3 安装 @nscode/handy-uni/web 预览插件。
示例
示例可独立运行;交互结果直接显示在页面。
vue
<template>
<view>
<hui-space direction="vertical" fill>
<hui-avatar-group
custom-class="hui-space__item"
:items="people"
:max="2"
@click="(_, context) => (lastEvent = String(context.index))"
@excess-click="(context) => (lastEvent = String(context.hidden.length))"
/>
<hui-avatar-group custom-class="hui-space__item" :overlap="false" size="small" shape="square"
><hui-avatar label="甲" /><hui-avatar label="乙"
/></hui-avatar-group>
<text class="hui-space__item">{{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const people = [
{ id: 1, label: '甲' },
{ id: 2, label: '乙' },
{ id: 3, label: '丙' }
]
</script>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
items | AvatarGroupItem[] | — | 数据驱动;传了才支持 max 截断 |
max | number | — | 最多显示几个,多出的合成一个“+N”;只对 items 生效 |
size | AvatarSize | 'default' | 组内头像的默认尺寸 |
shape | AvatarShape | 'circle' | shape 属性。 |
overlap | boolean | true | 叠放;叠放量用 --hui-avatar-group-overlap,默认尺寸的 25% |
itemKey | string | ((item: AvatarGroupItem) => string | number) | — | 列表 key;不传依次用 item.key、下标 |
根节点类名和样式使用 customClass、customStyle。尺寸数字按 px,时长除明确说明外按 ms。
Events
| 事件 | 参数 |
|---|---|
click | (item: AvatarGroupItem, context: { index: number }) |
excess-click | (context: { hidden: AvatarGroupItem[] }) |
受控状态由父级回写更新事件后改变。多词事件使用短横线。禁用操作、取消及过期异步结果不提交成功变更。
Slots
| 插槽 | 作用域 |
|---|---|
item | { item, index } |
excess | { count, hidden } |
default | — |
方法
无。
类型
AvatarGroupItem、AvatarGroupProps、AvatarGroupEmits.
平台说明
基于共享平台组件实现 H5、微信小程序、App-vue 与普通 Vue 3 Web。单元测试不代替设备验收;触摸、读屏、页面失活和原生组件表现按冒烟清单逐端核对。
设备冒烟清单.