Skip to content

Avatar 头像

用来代表用户或事物,支持图片、图标或字符展示。

基础用法

使用插槽

User
vue
<template>
  <ImAvatar>User</ImAvatar>
  <ImAvatar>
    <ImIcon name="user" />
  </ImAvatar>
</template>

图片方式

使用图片链接方式加载头像

vue
<template>
  <ImAvatar
    src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" />
  <ImAvatar src="https://avatars.githubusercontent.com/u/63175225?v=4" />
</template>

形状

通过设置 shape属性为 square circle 修改形状

vue
<template>
  <ImAvatar
    src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
  <ImAvatar src="https://avatars.githubusercontent.com/u/63175225?v=4" />
  <ImAvatar
    src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
    shape="square" />
  <ImAvatar
    src="https://avatars.githubusercontent.com/u/63175225?v=4"
    shape="square" />
</template>

API

字段名类型描述
sizenumber | string图片大小
srcstring图片源地址
altstring替代文本
titlestring标题文本
crossOriginstring跨域属性
fit'fill' | 'contain' | 'cover' | 'none' | 'scale-down'图片适应方式,默认为'fill'
srcsetstring多分辨率图片源
loading'eager' | 'lazy'加载策略,默认为'eager'
shape'circle' | 'square'形状,默认为'square'
colorstring图片颜色

基于 MIT 协议发布