For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/plugin/api-reference/ui/base-components/avatar.md.

VAvatar 头像

头像用于展示用户、应用或站点的图片标识。VAvatar 在图片加载失败时会显示 alt 的首字母作为占位,VAvatarGroup 用于把多个头像组合在一起。

引入

import { VAvatar, VAvatarGroup } from "@halo-dev/components";

示例

基础用法

<script lang="ts" setup>
import { VAvatar } from "@halo-dev/components";

const avatar = "https://www.halo.run/logo";
</script>

<template>
  <VAvatar :src="avatar" alt="Halo" />
</template>

不同尺寸

<script lang="ts" setup>
import { VAvatar, VSpace } from "@halo-dev/components";

const avatar = "https://www.halo.run/logo";
</script>

<template>
  <VSpace>
    <VAvatar :src="avatar" alt="Halo" size="xs" />
    <VAvatar :src="avatar" alt="Halo" size="sm" />
    <VAvatar :src="avatar" alt="Halo" size="md" />
    <VAvatar :src="avatar" alt="Halo" size="lg" />
  </VSpace>
</template>

圆形头像

<script lang="ts" setup>
import { VAvatar } from "@halo-dev/components";

const avatar = "https://www.halo.run/logo";
</script>

<template>
  <VAvatar :src="avatar" alt="Halo" circle />
</template>

无图片或加载失败

没有图片地址或图片无法加载时,会显示 alt 的首字母;没有 alt 时显示警告图标。

<script lang="ts" setup>
import { VAvatar, VSpace } from "@halo-dev/components";
</script>

<template>
  <VSpace>
    <VAvatar alt="Halo" />
    <VAvatar />
  </VSpace>
</template>

自定义尺寸

<script lang="ts" setup>
import { VAvatar } from "@halo-dev/components";

const avatar = "https://www.halo.run/logo";
</script>

<template>
  <VAvatar :src="avatar" alt="Halo" width="64px" height="64px" circle />
</template>

头像组

VAvatarGroup 会统一应用尺寸和形状,并让相邻头像产生重叠效果。

<script lang="ts" setup>
import { VAvatar, VAvatarGroup } from "@halo-dev/components";

const avatar = "https://www.halo.run/logo";
</script>

<template>
  <VAvatarGroup size="sm" circle>
    <VAvatar :src="avatar" alt="Halo" />
    <VAvatar :src="avatar" alt="Halo" />
    <VAvatar :src="avatar" alt="Halo" />
  </VAvatarGroup>
</template>

VAvatar Props

属性类型默认值说明
srcstringundefined图片地址
altstringundefined图片替代文本,加载失败时取其首字母作为占位
size"lg" | "md" | "sm" | "xs""md"头像尺寸
widthstringundefined自定义宽度,优先级高于 size
heightstringundefined自定义高度,优先级高于 size
circlebooleanfalse是否显示为圆形

VAvatarGroup Props

属性类型默认值说明
size"lg" | "md" | "sm" | "xs""md"组内头像尺寸,会覆盖 VAvatar 的同名属性
widthstringundefined组内头像宽度
heightstringundefined组内头像高度
circlebooleanfalse组内头像是否显示为圆形

Slots

组件插槽说明
VAvatarGroupdefault头像内容