当安装了 <NuxtImg> 组件时,Avatar 将使用它,@nuxt/image否则会回退到 img。
<img> 元素的任何属性,例如 alt、loading 等。使用 src 属性设置图片 URL。
<template>
<UAvatar src="https://github.com/benjamincanac.png" />
</template>
使用 size 属性设置 Avatar 的大小。
<template>
<UAvatar src="https://github.com/benjamincanac.png" size="xl" />
</template>
<img> 元素的 width 和 height 会根据 size 属性自动设置。使用 icon 属性显示备用 图标。
<template>
<UAvatar icon="i-lucide-image" size="md" />
</template>
使用 text 属性显示备用文本。
<template>
<UAvatar text="+1" size="md" />
</template>
当未提供图标或文本时,alt 属性的首字母将用作备用。
<template>
<UAvatar alt="Benjamin Canac" size="md" />
</template>
alt 属性会作为 alt 属性传递给 img 元素。使用 chip 属性在 Avatar 周围显示一个芯片。
<template>
<UAvatar
src="https://github.com/benjamincanac.png"
:chip="{
inset: true
}"
/>
</template>
您可以使用 Tooltip 组件在鼠标悬停 Avatar 时显示一个工具提示。
<template>
<UTooltip text="Benjamin Canac">
<UAvatar
src="https://github.com/benjamincanac.png"
alt="Benjamin Canac"
/>
</UTooltip>
</template>
您可以使用 CSS mask 来显示具有自定义形状而非简单圆形的 Avatar。
<template>
<UAvatar class="rounded-none squircle" src="https://avatars.githubusercontent.com/u/739984?v=4" alt="Benjamin Canac" />
</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>
| 属性 | 默认值 | 类型 |
|---|---|---|
as |
|
此组件应渲染为的元素或组件。 |
src |
| |
alt |
| |
图标 |
| |
文本 |
| |
尺寸 |
|
|
chip |
| |
ui |
|
export default defineAppConfig({
ui: {
avatar: {
slots: {
root: 'inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-elevated',
image: 'h-full w-full rounded-[inherit] object-cover',
fallback: 'font-medium leading-none text-muted truncate',
icon: 'text-muted shrink-0'
},
variants: {
size: {
'3xs': {
root: 'size-4 text-[8px]'
},
'2xs': {
root: 'size-5 text-[10px]'
},
xs: {
root: 'size-6 text-xs'
},
sm: {
root: 'size-7 text-sm'
},
md: {
root: 'size-8 text-base'
},
lg: {
root: 'size-9 text-lg'
},
xl: {
root: 'size-10 text-xl'
},
'2xl': {
root: 'size-11 text-[22px]'
},
'3xl': {
root: 'size-12 text-2xl'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
avatar: {
slots: {
root: 'inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-elevated',
image: 'h-full w-full rounded-[inherit] object-cover',
fallback: 'font-medium leading-none text-muted truncate',
icon: 'text-muted shrink-0'
},
variants: {
size: {
'3xs': {
root: 'size-4 text-[8px]'
},
'2xs': {
root: 'size-5 text-[10px]'
},
xs: {
root: 'size-6 text-xs'
},
sm: {
root: 'size-7 text-sm'
},
md: {
root: 'size-8 text-base'
},
lg: {
root: 'size-9 text-lg'
},
xl: {
root: 'size-10 text-xl'
},
'2xl': {
root: 'size-11 text-[22px]'
},
'3xl': {
root: 'size-12 text-2xl'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})
]
})