Badge Badge
Display counts, capped counts or dot notifications.
Import
Use <hui-badge> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
vue
<template>
<view>
<hui-badge :value="120" :max="99"><hui-button>消息 / Messages</hui-button></hui-badge>
<hui-badge dot><hui-button>新消息 / New</hui-button></hui-badge
><hui-badge :value="0" show-zero standalone /><hui-badge
value="New"
type="primary"
standalone
/>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | number | — | Option value or displayed value. |
max | number | 99 | Maximum selection count, numeric value or displayed count. |
dot | boolean | false | Display a dot instead of a count. |
showZero | boolean | false | Show the badge when the value is zero. |
type | BadgeType | 'danger' | Semantic type or input mode; see the type definition. |
color | string | — | Color override; prefer theme variables. |
offset | [number, number] | — | Badge offset or early loading distance, in px. |
hidden | boolean | false | Hide the badge. |
standalone | boolean | undefined | Display the badge standalone; derive from slot presence when omitted. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
None.
Slots
| Slot | Parameters | Description |
|---|---|---|
default | — | Main content. |
content | — | Custom content region; replaces its fallback content. |
Methods
None.
Types
BadgeProps、BadgeType are available from @nscode/handy-uni.
ts
export type BadgeType = 'danger' | 'primary' | 'success' | 'warning' | 'info'
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.