Skip to content

Badge ​

简易介绍 ​

badge徽章组件,用于在图标或文字旁显示未读消息数或状态标记。。
可以使用<MYBadge></MYBadge>或者<MYBadge />来实现一个徽章

数字内容 ​

使用content属性设置徽章内容。

代码演示
5
展开代码

小红点模式 ​

使用dot属性可以显示小红点而不显示具体数字。

代码演示
展开代码

自定义颜色 ​

使用color属性可以自定义徽章颜色。

代码演示
8
展开代码

位置调整 ​

使用position属性可以调整徽章的位置。

代码演示
3
3
3
3
展开代码

最大值限制 ​

使用max属性可以限制徽章显示的最大数值。

代码演示
99+
10+
5+
展开代码

独立使用 ​

徽章也可以独立使用,不包裹任何内容。

代码演示
5
新消息!
展开代码

组合使用 ​

最后,实现个多种api组合使用实现个徽章:

代码演示
展开代码

API 参考 ​

Props ​

参数说明类型可选值默认值
content徽章内容string | number—''
dot是否显示小红点boolean—false
color徽章颜色string支持16进制颜色或单词颜色'#ff4d4f'
position徽章位置stringtop-right/top-left/bottom-right/bottom-left'top-right'
max最大值限制number—99

类型定义 ​

typescript
interface BadgeProps {
  content?: string | number;
  dot?: boolean;
  color?: string;
  position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
  max?: number;
}

基于 MIT 协议