Skip to content

Avatar 头像

介绍

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

基础用法

支持三种尺寸:smallnormallarge

html
<template>
  <nut-avatar size="small">
    <image src="https://xxx.xx"></image>
  </nut-avatar>

  <nut-avatar size="normal">
    <image src="https://xxx.xx"></image>
  </nut-avatar>

  <nut-avatar size="large">
    <image src="https://xxx.xx"></image>
  </nut-avatar>
</template>

头像形状

支持两种形状:squareround

html
<template>
  <nut-avatar shape="square">
    <nut-icon name="my"></nut-icon>
  </nut-avatar>

  <nut-avatar shape="round">
    <nut-icon name="my"></nut-icon>
  </nut-avatar>
</template>

头像类型

支持三种类型:图片、Icon 以及字符。

html
<template>
  <nut-avatar>
    <image src="https://xxx.xx"></image>
  </nut-avatar>

  <nut-avatar>
    <nut-icon name="my"></nut-icon>
  </nut-avatar>

  <nut-avatar></nut-avatar>
</template>

自定义颜色及背景色

Icon 和字符型可以自定义颜色及背景色。

html
<template>
  <nut-avatar bg-color="#fa2c19">
    <nut-icon name="my" custom-color="#ffffff"></nut-icon>
  </nut-avatar>

  <nut-avatar custom-color="rgb(245, 106, 0)" bg-color="rgb(253, 227, 207)">小明</nut-avatar>
</template>

带徽标的头像

html
<template>
  <nut-badge value="8">
    <nut-avatar shape="square">
      <nut-icon name="my"></nut-icon>
    </nut-avatar>
  </nut-badge>

  <nut-badge dot>
    <nut-avatar shape="square">
      <nut-icon name="my"></nut-icon>
    </nut-avatar>
  </nut-badge>
</template>

头像组合展现

html
<template>
  <nut-avatar-group span="-4">
    <nut-avatar>
      <image src="https://xxx.xx"></image>
    </nut-avatar>

    <nut-avatar>
      <nut-icon name="my"></nut-icon>
    </nut-avatar>

    <nut-avatar custom-color="rgb(245, 106, 0)" bg-color="rgb(253, 227, 207)">小明</nut-avatar>
  </nut-avatar-group>

  <nut-avatar-group
    max-count="3"
    max-color="#ffffff"
    max-bg-color="#498ff2"
  >
    <nut-avatar>
      <image src="https://xxx.xx"></image>
    </nut-avatar>

    <nut-avatar>
      <nut-icon name="my"></nut-icon>
    </nut-avatar>

    <nut-avatar custom-color="rgb(245, 106, 0)" bg-color="rgb(253, 227, 207)">小明</nut-avatar>

    <nut-avatar>
      <nut-icon name="my"></nut-icon>
    </nut-avatar>
  </nut-avatar-group>
</template>

组合头像可控制层级方向

html
<template>
  <nut-avatar-group
    max-count="3"
    z-index="right"
    max-content="..."
  >
    <nut-avatar>
      <image src="https://xxx.xx"></image>
    </nut-avatar>

    <nut-avatar>
      <nut-icon name="my"></nut-icon>
    </nut-avatar>

    <nut-avatar custom-color="rgb(245, 106, 0)" bg-color="rgb(253, 227, 207)">小明</nut-avatar>

    <nut-avatar>
      <nut-icon name="my"></nut-icon>
    </nut-avatar>
  </nut-avatar-group>
</template>

API

Avatar Props

参数说明类型可选值默认值
size头像的大小,支持输入数字string / numberlarge / normal / smallnormal
shape头像的形状stringsquare / roundround
custom-color字体颜色string-#666
bg-color背景色string-#eee

Avatar Slots

名称说明
default默认插槽,可放置图片、图标、文本等元素

AvatarGroup Props

参数说明类型可选值默认值
max-count显示的最大头像个数(-1 表示无限制)string / number--1
max-content头像数量超出元素内容(默认为折叠元素数量)string--
size头像的大小,支持输入数字string / numberlarge / normal / smallnormal
shape头像的形状stringsquare / roundround
max-color头像折叠元素的字体颜色string-#666
max-bg-color头像折叠元素的背景色string-#eee
span头像之间的间距string / number--8
z-index组合头像之间的层级方向stringleft / rightleft

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-actionsheet-light-color#f6f6f6
--nut-avatar-square5px
--nut-avatar-large-width60px
--nut-avatar-large-height60px
--nut-avatar-small-width32px
--nut-avatar-small-height32px
--nut-avatar-normal-width40px
--nut-avatar-normal-height40px

MIT Licensed