Avatar.vue component is a reusable Vue.js component designed to display a circular avatar. It supports displaying an image if a src is provided or a text-based monogram if no image is available. The size of the avatar can be customized through props.
Features
Image or Monogram
Displays an image when the
src prop is provided or a text monogram when it is not.Custom Sizes
Supports three sizes:
large (default), small, and xSmall.Dynamic Content
Easily switch between image and monogram representations.
Usage
Basic Examples
Image Avatar
Monogram Avatar
Small Monogram Avatar
Extra Small Monogram Avatar
Props
The text displayed when no image source is provided.
Sets the avatar size to small.
Sets the avatar size to extra small.
The image source for the avatar. If not provided, displays the monogram.
Example Use Cases
Displaying a User’s Image
Use theAvatar component to display a user’s profile picture:
Fallback to Monogram
If an image is not available, the monogram will be displayed:Small and Extra Small Sizes
Adjust the size of the avatar using thesmall and xSmall props:
Notes
- Dynamic Size: The size is controlled by the
smallandxSmallprops, withlargebeing the default. - Image Fallback: If no
srcis provided, the component will render themonogramas a fallback. - Customizable: Combine this component with additional styling for unique use cases.