vant/src/notice-bar/README.md

4.0 KiB

NoticeBar

Intro

Used to display a group of message notifications in a continuons loop.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { NoticeBar } from 'vant';

const app = createApp();
app.use(NoticeBar);

Usage

Basic Usage

<van-notice-bar text="Notice Content" left-icon="volume-o" />

Scrollable

<!-- Enable scroll when text is short -->
<van-notice-bar scrollable text="Notice Content" />

<!-- Disable scroll when text is long -->
<van-notice-bar
  :scrollable="false"
  text="Technology is the common soul of the people who developed it."
/>

Wrapable

<van-notice-bar wrapable :scrollable="false">Notice Content</van-notice-bar>

Mode

<van-notice-bar mode="closeable">Notice Content</van-notice-bar>

<van-notice-bar mode="link">Notice Content</van-notice-bar>

Custom Style

<van-notice-bar color="#1989fa" background="#ecf9ff" left-icon="info-o">
  Notice Content
</van-notice-bar>

Vertical Scroll

<van-notice-bar left-icon="volume-o" :scrollable="false">
  <van-swipe
    vertical
    class="notice-swipe"
    :autoplay="3000"
    :show-indicators="false"
  >
    <van-swipe-item>Content 1</van-swipe-item>
    <van-swipe-item>Content 2</van-swipe-item>
    <van-swipe-item>Content 3</van-swipe-item>
  </van-swipe>
</van-notice-bar>

<style>
  .notice-swipe {
    height: 40px;
    line-height: 40px;
  }
</style>

API

Props

Attribute Description Type Default
mode Mode, can be set to closeable link string ''
text Notice text content string ''
color Text color string #f60
background Background color string #fff7cc
left-icon Left Icon string -
delay Animation delay (s) number | string 1
speed Scroll speed (px/s) number | string 60
scrollable Whether to scroll content boolean -
wrapable Whether to enable text wrap boolean false

Events

Event Description Arguments
click Emitted when NoticeBar is clicked event: MouseEvent
close Emitted when NoticeBar is closed event: MouseEvent
replay Emitted when NoticeBar is replayed -

Methods

Use ref to get NoticeBar instance and call instance methods.

Name Description Attribute Return value
reset v3.1.1 Reset NoticeBar - -

Types

Get the type definition of the NoticeBar instance through NoticeBarInstance.

import { ref } from 'vue';
import type { NoticeBarInstance } from 'vant';

const noticeBarRef = ref<NoticeBarInstance>();

noticeBarRef.value?.reset();

Slots

Name Description
default Notice text content
left-icon Custom left icon
right-icon Custom right icon

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

Name Default Value Description
--van-notice-bar-height 40px -
--van-notice-bar-padding 0 var(--van-padding-md) -
--van-notice-bar-wrapable-padding var(--van-padding-xs) var(--van-padding-md) -
--van-notice-bar-text-color var(--van-orange-dark) -
--van-notice-bar-font-size var(--van-font-size-md) -
--van-notice-bar-line-height 24px -
--van-notice-bar-background-color var(--van-orange-light) -
--van-notice-bar-icon-size 16px -
--van-notice-bar-icon-min-width 24px -