60 lines
1.3 KiB
Vue
60 lines
1.3 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
Avatar,
|
|
AvatarGroup,
|
|
AvatarImage,
|
|
AvatarFallback,
|
|
} from "@heroui-vue/components";
|
|
|
|
const users = [
|
|
{
|
|
id: 1,
|
|
image:
|
|
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
|
|
name: "张明",
|
|
},
|
|
{
|
|
id: 2,
|
|
image:
|
|
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
|
|
name: "李华",
|
|
},
|
|
{
|
|
id: 3,
|
|
image:
|
|
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
|
|
name: "王芳",
|
|
},
|
|
{
|
|
id: 4,
|
|
image:
|
|
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg",
|
|
name: "刘洋",
|
|
},
|
|
{
|
|
id: 5,
|
|
image:
|
|
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg",
|
|
name: "陈静",
|
|
},
|
|
];
|
|
|
|
function initialsFromName(name: string) {
|
|
const parts = name.split(/\s+/).filter(Boolean);
|
|
|
|
if (parts.length >= 2) {
|
|
return parts.map((n) => n[0]).join("");
|
|
}
|
|
|
|
return name.slice(0, 2);
|
|
}
|
|
</script>
|
|
<template>
|
|
<AvatarGroup is-grid :max="5">
|
|
<Avatar v-for="user in users" :key="user.id">
|
|
<AvatarImage :alt="`${user.name} 的头像`" :src="user.image" />
|
|
<AvatarFallback>{{ initialsFromName(user.name) }}</AvatarFallback>
|
|
</Avatar>
|
|
</AvatarGroup>
|
|
</template>
|