AvatarGroup
将多个头像堆叠成一组。
用法
将多个头像包裹在 AvatarGroup 中,使它们堆叠显示。



<template>
<UAvatarGroup>
<UAvatar src="https://github.com/benjamincanac.png" alt="Benjamin Canac" />
<UAvatar src="https://github.com/romhml.png" alt="Romain Hamel" />
<UAvatar src="https://github.com/noook.png" alt="Neil Richter" />
</UAvatarGroup>
</template>
尺寸
使用 size
属性来改变所有头像的大小。



<template>
<UAvatarGroup size="xl">
<UAvatar src="https://github.com/benjamincanac.png" alt="Benjamin Canac" />
<UAvatar src="https://github.com/romhml.png" alt="Romain Hamel" />
<UAvatar src="https://github.com/noook.png" alt="Neil Richter" />
</UAvatarGroup>
</template>
最大数量
使用 max
属性限制显示的头像数量。其余头像将显示为 +X
形式。
+1



<template>
<UAvatarGroup :max="2">
<UAvatar src="https://github.com/benjamincanac.png" alt="Benjamin Canac" />
<UAvatar src="https://github.com/romhml.png" alt="Romain Hamel" />
<UAvatar src="https://github.com/noook.png" alt="Neil Richter" />
</UAvatarGroup>
</template>
示例
带工具提示
将每个头像包裹在 Tooltip 中,以便在悬停时显示工具提示。



<template>
<UAvatarGroup>
<UTooltip text="benjamincanac">
<UAvatar
src="https://github.com/benjamincanac.png"
alt="Benjamin Canac"
/>
</UTooltip>
<UTooltip text="romhml">
<UAvatar
src="https://github.com/romhml.png"
alt="Romain Hamel"
/>
</UTooltip>
<UTooltip text="noook">
<UAvatar
src="https://github.com/noook.png"
alt="Neil Richter"
/>
</UTooltip>
</UAvatarGroup>
</template>
带芯片
将每个头像包裹在 Chip 中,以便在头像周围显示一个芯片。



<template>
<UAvatarGroup>
<UAvatar
src="https://github.com/benjamincanac.png"
alt="Benjamin Canac"
:chip="{ inset: true, color: 'success' }"
/>
<UAvatar
src="https://github.com/romhml.png"
alt="Romain Hamel"
:chip="{ inset: true, color: 'warning' }"
/>
<UAvatar
src="https://github.com/noook.png"
alt="Neil Richter"
:chip="{ inset: true, color: 'error' }"
/>
</UAvatarGroup>
</template>
带链接
将每个头像包裹在 Link 中,使它们可点击。
<template>
<UAvatarGroup>
<ULink
to="https://github.com/benjamincanac"
target="_blank"
class="hover:ring-primary transition"
raw
>
<UAvatar
src="https://github.com/benjamincanac.png"
alt="Benjamin Canac"
/>
</ULink>
<ULink
to="https://github.com/romhml"
target="_blank"
class="hover:ring-primary transition"
raw
>
<UAvatar
src="https://github.com/romhml.png"
alt="Romain Hamel"
/>
</ULink>
<ULink
to="https://github.com/noook"
target="_blank"
class="hover:ring-primary transition"
raw
>
<UAvatar
src="https://github.com/noook.png"
alt="Neil Richter"
/>
</ULink>
</UAvatarGroup>
</template>
带遮罩
用 CSS 遮罩包裹头像,以自定义形状显示。



<template>
<UAvatarGroup :ui="{ base: 'rounded-none squircle' }">
<UAvatar
src="https://github.com/benjamincanac.png"
alt="Benjamin Canac"
class="rounded-none squircle"
/>
<UAvatar
src="https://github.com/romhml.png"
alt="Romain Hamel"
class="rounded-none squircle"
/>
<UAvatar
src="https://github.com/noook.png"
alt="Neil Richter"
class="rounded-none squircle"
/>
</UAvatarGroup>
</template>
<style>
.squircle {
mask-image: url("data:image/svg+xml,%3csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M100 0C20 0 0 20 0 100s20 100 100 100 100-20 100-100S180 0 100 0Z'/%3e%3c/svg%3e");
mask-size: contain;
mask-position: center;
mask-repeat: no-repeat;
}
</style>
使用遮罩时,
chip
属性可能无法正常工作。芯片可能会根据遮罩形状被裁剪。API
属性
属性 | 默认值 | 类型 |
---|---|---|
as |
|
此组件应渲染为的元素或组件。 |
尺寸 |
|
|
max |
要显示的最大头像数量。 | |
ui |
|
插槽
插槽 | 类型 |
---|---|
default |
|
主题
app.config.ts
export default defineAppConfig({
ui: {
avatarGroup: {
slots: {
root: 'inline-flex flex-row-reverse justify-end',
base: 'relative rounded-full ring-bg first:me-0'
},
variants: {
size: {
'3xs': {
base: 'ring -me-0.5'
},
'2xs': {
base: 'ring -me-0.5'
},
xs: {
base: 'ring -me-0.5'
},
sm: {
base: 'ring-2 -me-1.5'
},
md: {
base: 'ring-2 -me-1.5'
},
lg: {
base: 'ring-2 -me-1.5'
},
xl: {
base: 'ring-3 -me-2'
},
'2xl': {
base: 'ring-3 -me-2'
},
'3xl': {
base: 'ring-3 -me-2'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
avatarGroup: {
slots: {
root: 'inline-flex flex-row-reverse justify-end',
base: 'relative rounded-full ring-bg first:me-0'
},
variants: {
size: {
'3xs': {
base: 'ring -me-0.5'
},
'2xs': {
base: 'ring -me-0.5'
},
xs: {
base: 'ring -me-0.5'
},
sm: {
base: 'ring-2 -me-1.5'
},
md: {
base: 'ring-2 -me-1.5'
},
lg: {
base: 'ring-2 -me-1.5'
},
xl: {
base: 'ring-3 -me-2'
},
'2xl': {
base: 'ring-3 -me-2'
},
'3xl': {
base: 'ring-3 -me-2'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})
]
})