Badge徽标数

Badge 徽标数

图标右上角的圆形徽标数字。

何时使用

一般出现在通知图标或头像的右上角,用于显示需要处理的消息条数,通过醒目视觉形式吸引用户处理。

代码演示

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

基本

简单的徽章展示,当 count 为 0 时,默认不显示,但是可以使用 showZero 修改为显示。

<​template>  <​a-badge count="5">    <​a href="#" class="head-example" />  <​/a-badge>  <​a-badge count="0" show-zero>    <​a href="#" class="head-example" />  <​/a-badge>  <​a-badge>    <​template #count>      <​clock-circle-outlined style="color: #f5222d" />    <​/template>    <​a href="#" class="head-example"><​/a>  <​/a-badge><​/template><​script lang="ts">import { defineComponent } from 'vue';import { ClockCircleOutlined } from '@ant-design/icons-vue';export default defineComponent({  components: {    ClockCircleOutlined,  },});<​/script>

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

99+10+999+

封顶数字

超过 overflowCount 的会显示为 ${overflowCount}+,默认的 overflowCount 为 99。

<​template>  <​a-badge :count="99">    <​a href="#" class="head-example" />  <​/a-badge>  <​a-badge :count="100">    <​a href="#" class="head-example" />  <​/a-badge>  <​a-badge :count="99" :overflow-count="10">    <​a href="#" class="head-example" />  <​/a-badge>  <​a-badge :count="1000" :overflow-count="999">    <​a href="#" class="head-example" />  <​/a-badge><​/template>

Success Error Default Processing warning

状态点

用于表示状态的小圆点。

<​template>  <​a-badge status="success" />  <​a-badge status="error" />  <​a-badge status="default" />  <​a-badge status="processing" />  <​a-badge status="warning" />  <​br />  <​a-badge status="success" text="Success" />  <​br />  <​a-badge status="error" text="Error" />  <​br />  <​a-badge status="default" text="Default" />  <​br />  <​a-badge status="processing" text="Processing" />  <​br />  <​a-badge status="warning" text="warning" /><​/template>

自定义标题

设置鼠标放在状态点上时显示的文字

<​template>  <​div id="components-badge-demo-title">    <​a-badge :count="5" title="Custom hover text">      <​a href="#" class="head-example" />    <​/a-badge>  <​/div><​/template><​style scoped>#components-badge-demo-title .ant-badge:not(.ant-badge-status) {  margin-right: 20px;}.head-example {  width: 42px;  height: 42px;  border-radius: 4px;  background: #eee;  display: inline-block;}<​/style>

[

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

](#)

可点击

用 a 标签进行包裹即可。

<​template>  <​a href="#">    <​a-badge count="5">      <​span class="head-example" />    <​/a-badge>  <​/a><​/template>

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

99+

独立使用

不包裹任何元素即是独立使用,可自定样式展现。 在右上角的 badge 则限定为红色。

<​template>  <​a-badge count="25" />  <​a-badge    count="4"    :number-style="{      backgroundColor: '#fff',      color: '#999',      boxShadow: '0 0 0 1px #d9d9d9 inset',    }"  />  <​a-badge count="109" :number-style="{ backgroundColor: '#52c41a' }" /><​/template>

讨嫌的小红点

没有具体的数字。

<​template>  <​div id="components-badge-demo-dot">    <​a-badge dot>      <​notification-outlined />    <​/a-badge>    <​a-badge :count="0" dot>      <​notification-outlined />    <​/a-badge>    <​a-badge dot>      <​a href="#">Link something<​/a>    <​/a-badge>  <​/div><​/template><​script lang="ts">import { defineComponent } from 'vue';import { NotificationOutlined } from '@ant-design/icons-vue';export default defineComponent({  components: {    NotificationOutlined,  },});<​/script><​style scoped>#components-badge-demo-dot .anticon-notification {  width: 16px;  height: 16px;  line-height: 16px;  font-size: 16px;}<​/style>

动态

展示动态变化的效果。

en-US

The count will be animated as it changes.

<​template>  <​div>    <​a-badge :count="count">      <​a href="#" class="head-example" />    <​/a-badge>    <​a-button-group>      <​a-button @click="decline">        <​minus-outlined />      <​/a-button>      <​a-button @click="increase">        <​plus-outlined />      <​/a-button>    <​/a-button-group>  <​/div>  <​div style="margin-top: 10px">    <​a-badge :dot="show">      <​a href="#" class="head-example" />    <​/a-badge>    <​a-switch v-model:checked="show" />  <​/div><​/template><​script lang="ts">import { defineComponent, ref } from 'vue';import { MinusOutlined, PlusOutlined } from '@ant-design/icons-vue';export default defineComponent({  components: {    MinusOutlined,    PlusOutlined,  },  setup() {    const count = ref<​number>(5);    const decline = () => {      if (count.value >= 1) {        count.value--;      }    };    const increase = () => {      count.value++;    };    return {      count,      show: ref<​boolean>(true),      decline,      increase,    };  },});<​/script>

Presets:

Custom:

多彩徽标

1.5.0 后新增。我们添加了多种预设色彩的徽标样式,用作不同场景使用。如果预设值不能满足你的需求,可以设置为具体的色值。

<​template>  <​h4 style="margin-bottom: 16px">Presets:<​/h4>  <​div>    <​div v-for="color in colors" :key="color">      <​a-badge :color="color" :text="color" />    <​/div>  <​/div>  <​h4 style="margin: 16px 0">Custom:<​/h4>  <​div>    <​a-badge color="#f50" text="#f50" />    <​br />    <​a-badge color="#2db7f5" text="#2db7f5" />    <​br />    <​a-badge color="#87d068" text="#87d068" />    <​br />    <​a-badge color="#108ee9" text="#108ee9" />  <​/div><​/template><​script lang="ts">import { defineComponent } from 'vue';const colors = [  'pink',  'red',  'yellow',  'orange',  'cyan',  'green',  'blue',  'purple',  'geekblue',  'magenta',  'volcano',  'gold',  'lime',];export default defineComponent({  setup() {    return {      colors,    };  },});<​/script>

API

<​a-badge :count="5">  <​a href="#" class="head-example" /><​/a-badge>
<​a-badge :count="5" />
参数 说明 类型 默认值 版本
color 自定义小圆点的颜色 string - 1.5.0

| count | 展示的数字,大于 overflowCount 时显示为 ${overflowCount}+,为 0 时隐藏 | number | string | slot | | | |---|---|---|---|---|

dot 不展示数字,只有一个小红点 boolean false

| offset | 设置状态点的位置偏移,格式为 [x, y] | [number|string, number|string] | - | | |---|---|---|---|---|

overflowCount 展示封顶的数字值 number 99
showZero 当数值为 0 时,是否展示 Badge boolean false
status 设置 Badge 为状态点 Enum{ ‘success’, ‘processing, ‘default’, ‘error’, ‘warning’ } ‘’
text 在设置了 status 的前提下有效,设置状态点的文本 string ‘’
numberStyle 设置状态点的样式 object ‘’
title 设置鼠标放在状态点上时显示的文字 string count