Skip to content

Notice Bar 通知栏

用于展示系统公告、活动提醒、滚动消息等强调性文本,支持静态、横向滚动、竖向轮播三种展示方式。

交互式调试

🔧调试模式Playground

基础用法

vue
<lk-notice-bar text="这是一条通知" scrollable="horizontal" />

横向滚动

当文案较长时,推荐开启横向滚动,并通过 speed 控制节奏。

vue
<lk-notice-bar
  text="系统升级通知:今晚 22:00-23:00 将进行系统维护,请提前保存数据。"
  scrollable="horizontal"
  :speed="15"
/>

竖向轮播

用于多条通知逐条轮播展示。竖向模式优先读取 messages

vue
<script setup lang="ts">
const messages = [
  '📢 您有新的订单待处理',
  '🎁 双11 活动即将开始',
  '⚠️ 请及时更新个人信息',
]
</script>

<template>
  <lk-notice-bar scrollable="vertical" :messages="messages" :speed="3" />
</template>

可关闭

vue
<lk-notice-bar
  text="这是一条可以关闭的通知"
  closeable
  @close="show = false"
/>

自定义左右区域

支持自定义左侧图标、右侧操作区与右侧图标区。

vue
<lk-notice-bar text="点击右侧查看详情">
  <template #left-icon>
    <lk-icon name="info-circle-fill" size="32" />
  </template>

  <template #right>
    <view class="link-text">详情 ></view>
  </template>
</lk-notice-bar>

自定义颜色与无背景

vue
<template>
  <lk-notice-bar text="自定义颜色消息" color="#ff6b6b" background="#ffe0e0" />
  <lk-notice-bar text="无背景通知" no-background scrollable="horizontal" />
</template>

推荐示例

1) 直接复用项目 Demo(推荐)

vue
<script setup lang="ts">
import NoticeBarDemo from '@/components/demos/notice-bar-demo.vue'
</script>

<template>
  <NoticeBarDemo />
</template>

2) 在业务页中按需组合

vue
<template>
  <view class="page-demo">
    <lk-notice-bar />
  </view>
</template>

API

Props

参数说明类型默认值
text通知文本string''
scrollable滚动模式;false 不滚动,true 等价于横向滚动boolean | 'horizontal' | 'vertical'horizontal
speed滚动速度或竖向轮播停留时长(秒)number10
closeable是否可关闭booleanfalse
icon左侧图标名string''
color文本颜色stringvar(--lk-color-warning)
background背景色stringvar(--lk-fill-1)
noBackground是否移除背景与默认文字色注入booleanfalse
messages竖向滚动时的消息数组string[][]
id根节点 idstring''
customClass根节点自定义类名string | object | array
customStyle根节点自定义样式string | object

Events

事件名说明参数
click点击通知栏主体({ text, index, event }) => void
close点击关闭按钮(event?: Event) => void
message-change竖向轮播切换消息时触发({ index, text }) => void
loop-reset竖向轮播无缝重置到第一条时触发() => void

Slots

插槽名说明
default自定义主体文本内容
left-icon左侧图标区域
right右侧完整操作区域
right-icon右侧图标区域;仅在未提供 right 时使用

使用建议

TIP

单条长文案优先用横向滚动;多条消息优先用竖向轮播,这样阅读负担更低。

WARNING

speed 在横向与竖向模式下都以秒为单位,但语义不同:横向是动画时长,竖向是每条停留时长。

基于 MIT 协议开源 · 粤ICP备2022114240号-3

Notice Bar 通知栏

正在连接预览服务...

请先运行 pnpm run dev:h5