NoticeBar
Displays static, wrapped, horizontally scrolling or vertically rotating notices.
Import
Use <hui-notice-bar> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-space direction="vertical" fill>
<hui-notice-bar
custom-class="hui-space__item"
text="公告:请及时保存 / Notice: save your work."
closable
@close="lastEvent = 'close'"
@click="(context) => (lastEvent = 'click:' + JSON.stringify(context))"
/>
<hui-notice-bar
custom-class="hui-space__item"
:text="['第一条 / First', '第二条 / Second']"
direction="vertical"
:interval="2500"
@next="(index) => (lastEvent = 'next:' + index)"
@replay="lastEvent = 'replay'"
/>
<hui-notice-bar
custom-class="hui-space__item"
text="长公告 / Long notice. Long notice. Long notice."
wrapable
:scrollable="false"
type="info"
/>
<text class="hui-space__item">{{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
text | string | string[] | — | Text content; NoticeBar also accepts a list. |
type | NoticeBarType | 'warning' | Semantic visual variant. |
color | string | — | Explicit foreground or progress color; arrays provide evenly spaced color stops. |
bgColor | string | — | Explicit background color. |
leftIcon | string | 'volume-up' | Leading icon; an empty string hides it. |
scrollable | boolean | undefined | Forces or disables horizontal scrolling; omitted means overflow-only. |
wrapable | boolean | false | Wraps text and disables scrolling. |
direction | NoticeBarDirection | 'horizontal' | Layout or scrolling direction. |
speed | number | 50 | Horizontal scrolling speed in px/s; must be positive. |
delay | number | 1000 | Delay before horizontal scrolling, in ms. |
interval | number | 3000 | Autoplay or rotation interval in ms. |
closable | boolean | false | Displays a close control. |
link | boolean | false | Displays a navigation affordance. |
to | string | — | Navigation target resolved by the router adapter. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
click | (context: { text: string; index: number }) |
close | () |
next | (index: number) |
replay | () |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
left-icon | — |
default | — |
right-icon | — |
Methods
| Method | Signature | Description |
|---|---|---|
reset | (): Promise<void> | Reset from current props. |
pause | (): void | Pause and preserve remaining state. |
resume | (): void | Resume a paused animation. |
Types
NoticeBarType、NoticeBarDirection、NoticeBarProps、NoticeBarEmits、NoticeBarExpose.
Platform notes
H5 and ordinary Web honor reduced-motion preferences by displaying static wrapped text. Mini-program and App behavior follows notice settings. Speed uses px/s; other durations use ms. Deactivation and disposal clean timers; reset measures again.
Device smoke checklist.