Skip to content

Avatar 头像

基础用法

html

<script setup lang="ts">
const image = 'https://pic2.imgdb.cn/item/644bf4470d2dde5777abf840.webp'
</script>

<template>
  <AAvatar :src="image" size="mini" />
  <AAvatar :src="image" size="small" />
  <AAvatar src="https://pic2.imgdb.cn/item/644bf3c40d2dde5777ab58cb.png" size="normal" />
  <AAvatar :src="image" size="large" />
  <AAvatar :src="image" custom-class="h-16 w-16" />
</template>

<script setup lang="ts">
const image = 'https://pic2.imgdb.cn/item/644bf4470d2dde5777abf840.webp'
</script>

<template>
  <AAvatar :src="image" size="mini" />
  <AAvatar :src="image" size="small" />
  <AAvatar src="https://pic2.imgdb.cn/item/644bf3c40d2dde5777ab58cb.png" size="normal" />
  <AAvatar :src="image" size="large" />
  <AAvatar :src="image" custom-class="h-16 w-16" />
</template>

圆形

html
<template>
  <AAvatar :src="image" custom-class="rounded-full" size="mini" />
  <AAvatar :src="image" custom-class="rounded-full" size="small" />
  <AAvatar :src="image" custom-class="rounded-full" size="normal" />
  <AAvatar :src="image" custom-class="rounded-full" size="large" />
</template>
<template>
  <AAvatar :src="image" custom-class="rounded-full" size="mini" />
  <AAvatar :src="image" custom-class="rounded-full" size="small" />
  <AAvatar :src="image" custom-class="rounded-full" size="normal" />
  <AAvatar :src="image" custom-class="rounded-full" size="large" />
</template>

自定义

html
<template>
  <AAvatar custom-class="rounded-full bg-primary text-white">
    T
  </AAvatar>
  <AAvatar custom-class="rounded-full bg-primary text-white">
    <div class="i-tabler-loader" />
  </AAvatar>
</template>
<template>
  <AAvatar custom-class="rounded-full bg-primary text-white">
    T
  </AAvatar>
  <AAvatar custom-class="rounded-full bg-primary text-white">
    <div class="i-tabler-loader" />
  </AAvatar>
</template>

头像组

html

<script setup lang="ts">
const image = 'https://pic2.imgdb.cn/item/644bf4470d2dde5777abf840.webp'
const options = ref([
  { src: image },
  { src: image },
  { src: image },
  { src: image },
  { src: image },
])
</script>

<template>
  <AAvatarGroup :max="3" :options="options" />
  <AAvatarGroup :max="3" :options="options">
    <template #avatar="{ option: { src } }">
      <AAvatar custom-class="rounded-full" :src="src" />
    </template>
    <template #reset="{ reset }">
      <AAvatar custom-class="z-1 rounded-full bg-primary text-white">
        +{{ reset }}
      </AAvatar>
    </template>
  </AAvatarGroup>
</template>

<script setup lang="ts">
const image = 'https://pic2.imgdb.cn/item/644bf4470d2dde5777abf840.webp'
const options = ref([
  { src: image },
  { src: image },
  { src: image },
  { src: image },
  { src: image },
])
</script>

<template>
  <AAvatarGroup :max="3" :options="options" />
  <AAvatarGroup :max="3" :options="options">
    <template #avatar="{ option: { src } }">
      <AAvatar custom-class="rounded-full" :src="src" />
    </template>
    <template #reset="{ reset }">
      <AAvatar custom-class="z-1 rounded-full bg-primary text-white">
        +{{ reset }}
      </AAvatar>
    </template>
  </AAvatarGroup>
</template>

API

Props

参数说明类型默认值
size可选值为 mini small normal' largestringnormal
src图片链接string-
fit图片填充模式,等同于原生的 object-fit 属性stringcover

Events

事件名说明回调参数
click点击头像时触发event: MouseEvent

Slots

名称说明
default自定义头像内容

MIT Licensed