Badge 徽标
uni-appH5微信小程序App
uni-app 跨端徽标组件。可显示数字、小红点或封顶数字,常用于图标或头像右上角。
何时使用
用于提示未读数量或需要用户注意的状态。
何时不使用
徽标数字过大或需要精确计数时,应考虑列表详情页。
本文档为 uni-app 端组件契约;Web 端同名组件 API 可能略有差异,请以对应包文档为准。下方手机预览实时运行 uni-app H5 演示。
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
content | string | number | - | 徽标内容;数字超过 max 时显示为 {max}+ |
dot | boolean | false | 是否只显示小红点 |
max | number | - | 数字上限,超过时显示 {max}+ |
value | string | number | "undefined" | 徽标内容,通常为计数数字 |
showZero | boolean | false | value 为 0 时是否仍显示徽标 |
offset | [number, number] | "undefined" | 徽标相对右上角的位置微调 [x, y],单位 px |
Slots
| 名称 | 说明 |
|---|---|
default | 被包裹的元素,如图标、头像 |
示例
数字徽标
vue
<view class="row">
<Badge :content="8"><view class="badge-anchor" /></Badge>
<Badge :content="16"><Icon name="bell" :size="24" /></Badge>
<Badge content="NEW"><Icon name="mail" :size="24" /></Badge>
</view>最大值
vue
<view class="row">
<Badge :content="123" :max="99"><view class="badge-anchor" /></Badge>
<Badge :content="12" :max="10"><view class="badge-anchor" /></Badge>
</view>小红点
vue
<view class="row">
<Badge dot><view class="badge-anchor" /></Badge>
<Badge dot><Icon name="mail" :size="24" /></Badge>
</view>value / showZero / 偏移
vue
<view class="row">
<Badge :value="66"><Icon name="bell" :size="24" /></Badge>
<Badge :value="0" show-zero><Icon name="mail" :size="24" /></Badge>
<Badge :value="5" :offset="[6, -4]"><view class="badge-anchor" /></Badge>
</view>