组件
头像 Avatar
Avatar:头像组件。先在内凹纸面上显示首字母,图片加载完成后覆盖显示。`size` 从控件高度阶梯中取一档,core 样式会按档位改写 `--bs-avatar-size`,场景仍可直接调整这个变量。
#基础用法
S
BS
墨
印
<script setup lang="ts">
import { Avatar } from "@bysages/vue";
const PORTRAIT =
"data:image/svg+xml;utf8," +
encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="144" height="144"><rect width="144" height="144" fill="#b9b2a4"/><circle cx="72" cy="56" r="26" fill="#3a3733"/><path d="M24 132c6-30 26-44 48-44s42 14 48 44" fill="#3a3733"/></svg>`,
);
</script>
<template>
<div class="flex gap-3 items-center">
<Avatar.Root>
<Avatar.Fallback>S</Avatar.Fallback>
<Avatar.Image :src="PORTRAIT" alt="Portrait of Sage" />
</Avatar.Root>
<Avatar.Root>
<Avatar.Fallback>BS</Avatar.Fallback>
</Avatar.Root>
</div>
<div class="mt-4 flex items-center gap-3">
<Avatar.Root>墨</Avatar.Root>
<Avatar.Root shape="square">印</Avatar.Root>
</div>
</template>
#属性
#Fallback
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Image
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Root
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
size | String as PropType<AvatarSize> | "md" | 头像直径,取控件高度档位;默认 md,与其他控件对齐,头像随行显示时不会撑高行 |
shape | String as PropType<"circle" | "square"> | "circle" | 头像形状,可为 circle 或 square;默认 circle |
id | string | 组件内部状态机的唯一标识 | |
ids | Partial<{ root: string; image: string; fallback: string; }> | 头像内各元素的 id;便于组合使用 |