Skip to content

NoticeBar ​

17:06

Description ​

Scrolls notifications, announcements, etc. Content comes from the list array and supports success/error/primary/info/warning/none themes, custom text/background colors, left/right icons and a close button, with play-state toggling play and pause. Horizontal mode uses seamless scrolling by default, while vertical mode switches items one by one via a swiper; the two are handled internally by ux-row-notice and ux-column-notice respectively.

Compatibility ​

PlatformSupport
App✅ Supported
H5✅ Supported
WeChat Mini Program✅ Supported

Examples ​

Horizontal - Basic Usage ​

Configure the scrolling content via the list array; defaults to the warning theme and scrolls horizontally.

View source
vue
<template>
    <ux-notice-bar :list="list" @click="onClick"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];

function onClick(): void {
    uni.showToast({ title: '点击了通知', icon: 'none' });
}
</script>

Horizontal - Configure Theme ​

Configure success/error/primary/info/warning/none themes via type.

View source
vue
<template>
    <ux-notice-bar type="primary" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar type="success" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar type="error" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar type="info" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar type="none" :list="list"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>

<style scoped>
.gap {
    height: 12px;
}
</style>

Horizontal - Configure Icons ​

volume-icon is the speaker on the left, more-icon is the arrow on the right, and close-icon is the close button on the right.

View source
vue
<template>
    <ux-notice-bar :volume-icon="false" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar :more-icon="true" :list="list" @get-more="onGetMore"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar :close-icon="true" :list="list" @close="onClose"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];

function onGetMore(): void {
    uni.showToast({ title: '点击了更多', icon: 'none' });
}

function onClose(): void {
    uni.showToast({ title: '关闭了通知', icon: 'none' });
}
</script>

<style scoped>
.gap {
    height: 12px;
}
</style>

Horizontal - Custom Color ​

Customize the text/icon color and background color via color/bg-color.

View source
vue
<template>
    <ux-notice-bar color="#2979ff" bg-color="#ecf5ff" :list="list"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>

Horizontal - Control Scrolling ​

autoplay controls auto-play, play-state controls play/pause, and speed controls the speed.

View source
vue
<template>
    <ux-notice-bar :speed="200" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar :play-state="playState" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <view class="btn" @click="onToggle">
        <text class="btn-text">{{ playing ? '暂停' : '播放' }}</text>
    </view>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];

const playing = ref<boolean>(true);
const playState = ref<string>('play');

function onToggle(): void {
    playing.value = !playing.value;
    playState.value = playing.value ? 'play' : 'paused';
}
</script>

<style scoped>
.gap {
    height: 12px;
}
.btn {
    background-color: #2979ff;
    border-radius: 4px;
    padding-top: 8px;
    padding-right: 16px;
    padding-bottom: 8px;
    padding-left: 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}
.btn-text {
    font-size: 14px;
    color: #ffffff;
}
</style>

Vertical - Basic Usage ​

Configure the scrolling content via the list array; defaults to the warning theme and scrolls vertically.

View source
vue
<template>
    <ux-notice-bar mode="vertical" :list="list" @click="onClick"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];

function onClick(): void {
    uni.showToast({ title: '点击了通知', icon: 'none' });
}
</script>

Vertical - Configure Theme ​

Configure success/primary/info/none themes via type.

View source
vue
<template>
    <ux-notice-bar mode="vertical" type="primary" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" type="success" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" type="info" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" type="none" :list="list"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>

<style scoped>
.gap {
    height: 12px;
}
</style>

Vertical - Configure Icons ​

volume-icon is the speaker on the left, more-icon is the arrow on the right, and close-icon is the close button on the right.

View source
vue
<template>
    <ux-notice-bar mode="vertical" :volume-icon="false" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" :more-icon="true" :list="list" @get-more="onGetMore"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" :close-icon="true" :list="list" @close="onClose"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];

function onGetMore(): void {
    uni.showToast({ title: '点击了更多', icon: 'none' });
}

function onClose(): void {
    uni.showToast({ title: '关闭了通知', icon: 'none' });
}
</script>

<style scoped>
.gap {
    height: 12px;
}
</style>

Vertical - Custom Color ​

Customize the text/icon color and background color via color/bg-color.

View source
vue
<template>
    <ux-notice-bar mode="vertical" color="#2979ff" bg-color="#ecf5ff" :list="list"></ux-notice-bar>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>

Vertical - Control Scrolling ​

play-state controls play/pause, duration controls the scroll cycle, and disable-touch prevents manual swiping.

View source
vue
<template>
    <ux-notice-bar mode="vertical" :play-state="playState" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" :duration="4000" :list="list"></ux-notice-bar>
    <view class="gap"></view>
    <ux-notice-bar mode="vertical" :disable-touch="false" :list="list" @end="onEnd"></ux-notice-bar>
    <view class="gap"></view>
    <view class="btn" @click="onToggle">
        <text class="btn-text">{{ playing ? '暂停' : '播放' }}</text>
    </view>
</template>

<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];

const playing = ref<boolean>(true);
const playState = ref<string>('play');

function onToggle(): void {
    playing.value = !playing.value;
    playState.value = playing.value ? 'play' : 'paused';
}

function onEnd(): void {
    uni.showToast({ title: '轮播结束', icon: 'none' });
}
</script>

<style scoped>
.gap {
    height: 12px;
}
.btn {
    background-color: #2979ff;
    border-radius: 4px;
    padding-top: 8px;
    padding-right: 16px;
    padding-bottom: 8px;
    padding-left: 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}
.btn-text {
    font-size: 14px;
    color: #ffffff;
}
</style>

API ​

Props ​

PropertyDescriptionTypeDefaultVersion
customStyleCustom style for the root nodeUTSJSONObject--
customClassCustom class for the root nodestring''-
listScrolling content, as an arraystring[]--
typeTheme: success/error/primary/info/warning/noneThemeType | 'none''warning'-
volumeIconWhether to show the speaker icon on the leftbooleantrue-
volumeSizeSize of the left speaker icon, in pxnumber | string17-
moreIconWhether to show the arrow icon on the rightbooleanfalse-
closeIconWhether to show the close icon on the rightbooleanfalse-
autoplayWhether to auto-play (currently not forwarded to the inner child components)booleantrue-
colorText color; the icons use it as wellstring''-
bgColorBackground colorstring''-
modeScroll direction: horizontal / verticalDirection'horizontal'-
showWhether to show the componentbooleantrue-
fontSizeFont size, in pxnumber | string14-
durationSwitch interval per item, in ms (swiper mode only)number | string2000-
speedSeamless horizontal scroll speed, in px per second (horizontal seamless mode only)number | string80-
isCircularWhether to enable seamless horizontal scrolling (horizontal direction only)booleantrue-
playStatePlayback state: play / pausedPlayState'play'-
disableTouchWhether to disable manual swipe switching (swiper mode only)booleantrue-
borderRadiusCorner radius, in px (applied when greater than 0)number | string0-
paddingInner paddingnumber | string'9px 12px'-
noListHiddenWhether to hide when list is emptybooleantrue-

Events ​

EventDescriptionParamsVersion
clickEmitted when the notice text is tapped; index is the item index (always 0 in horizontal seamless mode)index: number-
closeEmitted when the close icon is tapped--
getMoreEmitted when the right more arrow is tapped--
endEmitted when scrolling reaches the last item (swiper mode only)--

Slots ​

ux-notice-bar has no slots.

Notes ​

  1. The internal implementation depends on mode and isCircular: with mode='horizontal' and isCircular=true it uses ux-row-notice for seamless scrolling; otherwise (isCircular=false horizontal, or mode='vertical') it uses the swiper inside ux-column-notice to switch items one by one.
  2. isCircular only takes effect in the horizontal direction; vertical always uses the swiper.
  3. Horizontal seamless mode joins list into one continuous string with a Chinese comma "," and scrolls it; the click callback index is always 0. Only swiper mode shows items one by one and returns the real index.
  4. Seamless scrolling only runs when a single text's width exceeds the container width; short content stays static.
  5. speed works only in horizontal seamless mode, while duration and disableTouch work only in swiper mode; do not mix them.
  6. end fires only in swiper mode when scrolling reaches the last item.
  7. autoplay is currently not forwarded to the inner child components; use play-state='paused' to pause instead.
  8. With type='none' there is no background (transparent) and the text uses the content color; other themes use a light background with theme-colored text.
  9. noListHidden defaults to true, so the whole component is hidden when list is empty; show=false also hides it.