vue-avatar-3
vue-avatar-3
A useful avatar component for Vue 3, with support for letter avatars. Inspired by react-avatar.
Live demo: https://stackblitz.com/edit/vue-avatar-3.
Installation
npm install vue-avatar-3
yarn
yarn add vue-avatar-3
pnpm
pnpm add vue-avatar-3
Usage
<script setup>
import { ref } from 'vue'
import Avatar from 'vue-avatar-3'
const src = ref('https://fakeimg.pl/300/')
const name = ref('Foo Bar')
</script>
<template>
<Avatar :src="src" :name="name" />
</template>
The priority of displaying avatars is as follows:
- If
srcis set, thensrcwill have the highest priority. - If
srcis not set or the load fails, then thenamewill be used to generate a letter avatar (you can usefallbackto control this behavior).
Options
| Name | Type | Default | Description |
|---|---|---|---|
src |
string |
The image source. | |
alt |
string |
The image alt. | |
srcSet |
string |
The image srcSet. | |
sizes |
string |
The image sizes. | |
imgProps |
object |
The image attributes that will be applied to the image. This option will override above options. | |
name |
string |
Specify a name to generate a letter avatar. This option will only take effect if the image is not loaded successfully and the fallback option is true. |
|
bgColor |
string |
Specify a background color for the letter avatar (use a 3- or 6-digit hex color so the text color can be determined automatically). | |
size |
string / number |
40px |
The size of the avatar. You can use a number or a string with a unit. |
variant |
circular / rounded / square |
circular |
The variant of the avatar. |
round |
string / number |
8px |
The radius of the avatar. Take effect when variant is rounded. You can use a number or a string with a unit. |
fallback |
boolean |
true |
Whether to show the letter avatar when the image is not loaded successfully. |
Credits
This project is inspired by the following projects:
License
Released under the MIT License.
Related Packages
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 1.0.0 | ^3.0.0 | MIT | |
| 0.3.1 | ^3.0.0 || | MIT | |
| 0.3.0 | ^3.0.0 || | MIT | |
| 0.2.4 | ^3.0.0 || | MIT | |
| 0.2.3 | ^3.0.0 || | MIT | |
| 0.2.2 | ^3.0.0 || | MIT | |
| 0.2.1 | ^3.0.0 || | MIT | |
| 0.2.0 | ^3.0.0 || | MIT | |
| 0.1.0 | MIT |