Skip to content

NoticeBar 通知栏

用于展示通知、公告等滚动消息,支持水平滚动、垂直轮播、可关闭等特性。

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

  • 通过 text 设置通知文字内容。
html
<see-notice-bar text="这是一条通知消息,内容超出时会自动滚动。" />

通知类型

  • 通过 type 设置通知类型,默认为 info
html
<see-notice-bar type="info" text="这是一条信息通知。" />
<see-notice-bar type="warning" text="这是一条警告通知。" />
<see-notice-bar type="error" text="这是一条错误通知。" />

滚动控制

  • 默认开启滚动,通过设置 isScrollablefalse 可关闭滚动。
  • 通过 speed 设置滚动速度,单位为 px/s,默认 50。
  • 通过 delay 设置滚动开始前的停顿时间,单位为 ms,默认 1000。
html
<see-notice-bar text="默认滚动速度的通知消息。" />
<see-notice-bar text="快速滚动的通知消息。" :speed="100" />
<see-notice-bar text="停顿更久再滚动。" :delay="3000" />
<see-notice-bar is-scrollable="false" text="不滚动的通知消息,内容超出时将被截断。" />

触摸暂停

  • 默认触摸时暂停滚动,通过设置 isPauseOnTouchfalse 可关闭此行为。
html
<see-notice-bar text="触摸时会暂停滚动,松开后继续。" />
<see-notice-bar is-pause-on-touch="false" text="触摸时不会暂停滚动。" />

可关闭

  • 通过设置 isClosabletrue 显示关闭按钮。
  • 关闭时会触发 onClose 事件。
html
<see-notice-bar is-closable text="这是一条可关闭的通知消息。" />

图标

  • 默认显示左侧图标,通过设置 isShowIconfalse 可隐藏图标。
  • 通过 icon 自定义左侧图标,默认为 🔊
  • 通过 rightIcon 设置右侧图标。
html
<see-notice-bar text="默认带喇叭图标的通知。" />
<see-notice-bar is-show-icon="false" text="没有图标的通知。" />
<see-notice-bar icon="📢" text="自定义左侧图标的通知。" />
<see-notice-bar right-icon="➡️" text="带右侧图标的通知。" />

垂直轮播

  • 通过设置 verticaltrue 启用垂直轮播模式。
  • 通过 messages 传入多条消息。
  • 通过 verticalInterval 设置轮播间隔,单位为 ms,默认 3000。
html
<see-notice-bar
  vertical
  :messages="['第一条通知消息', '第二条通知消息', '第三条通知消息']"
/>
<see-notice-bar
  vertical
  :messages="['快速轮播消息一', '快速轮播消息二']"
  :vertical-interval="1500"
/>

受控显示

  • 通过 isShow(v-model)控制通知栏的显示与隐藏。
html
<see-notice-bar v-model:isShow="visible" text="通过 v-model 控制显示状态。" />

自定义插槽

  • 通过 left 插槽自定义左侧内容。
  • 通过 right 插槽自定义右侧内容。
html
<see-notice-bar text="自定义左侧和右侧内容。">
  <template #left>
    <text>自定义左侧</text>
  </template>
  <template #right>
    <text>自定义右侧</text>
  </template>
</see-notice-bar>

API

Props

参数名说明类型默认值
text通知文字String''
type通知类型'info' | 'warning' | 'error''info'
speed滚动速度(px/s)Number50
isScrollable是否滚动Booleantrue
delay滚动开始前停顿(ms)Number1000
isClosable是否可关闭Booleanfalse
isShowIcon是否显示左侧图标Booleantrue
icon自定义左侧图标String'🔊'
rightIcon右侧图标String''
isShow是否显示(v-model)Booleantrue
isPauseOnTouch触摸时是否暂停滚动Booleantrue
vertical是否垂直滚动(多消息轮播)Booleanfalse
messages多条消息(vertical=true 时使用)String[][]
verticalInterval垂直轮播间隔(ms)Number3000

Events

属性名说明
onClick点击通知栏时触发
onClose关闭时触发
onRightClick点击右侧图标时触发
update:isShowv-model 更新

Slots

插槽名说明
left自定义左侧内容
right自定义右侧内容

辽 ICP 备 2025070134 号