import{o as t,a,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=n(`

Notify

Intro

The display message prompt is at the top of the page, and supports two methods: function call and component call.

Install

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

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

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

Usage

Basic Usage

Notify('Notify Message');

Notify Type

Notify({ type: 'primary', message: 'Notify Message' });
Notify({ type: 'success', message: 'Notify Message' });
Notify({ type: 'danger', message: 'Notify Message' });
Notify({ type: 'warning', message: 'Notify Message' });

Custom Notify

Notify({
  message: 'Custom Color',
  color: '#ad0000',
  background: '#ffe1e1',
});

Notify({
  message: 'Custom Position',
  position: 'bottom',
});

Notify({
  message: 'Custom Duration',
  duration: 1000,
});

Global Method

After registering the Notify component through app.use, the $notify method will be automatically mounted on all subcomponents of the app.

export default {
  mounted() {
    this.$notify('Notify Message');
  },
};

Component Call

<van-button type="primary" text="Component Call" @click="showNotify" />
<van-notify v-model:show="show" type="success">
  <van-icon name="bell" style="margin-right: 4px;" />
  <span>Content</span>
</van-notify>
import { ref } from 'vue';

export default {
  setup() {
    const show = ref(false);

    const showNotify = () => {
      show.value = true;
      setTimeout(() => {
        show.value = false;
      }, 2000);
    };

    return {
      show,
      showNotify,
    };
  },
};

API

Methods

MethodsAttributeReturn valueDescription
Notifyoptions | messagenotify instanceShow notify
Notify.clear-voidClose notify
Notify.setDefaultOptionsoptionsvoidSet default options of all notifies
Notify.resetDefaultOptions-voidReset default options of all notifies

Options

AttributeDescriptionTypeDefault
typeCan be set to primary success warningNotifyTypedanger
messageMessagestring-
durationDuration(ms), won't disappear if value is 0number | string3000
position v3.4.0Position, can be set to bottomNotifyPositiontop
colorMessage colorstringwhite
backgroundBackground colorstring-
classNameCustom classNamestring | Array | object-
lockScroll v3.0.7Whether to lock background scrollbooleanfalse
onClickCallback function after click(event: MouseEvent) => void-
onOpenedCallback function after opened() => void-
onCloseCallback function after close() => void-

Types

The component exports the following type definitions:

import type {
  NotifyType,
  NotifyProps,
  NotifyOptions,
  NotifyPosition,
} from 'vant';

Theming

CSS Variables

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

NameDefault ValueDescription
--van-notify-text-colorvar(--van-white)-
--van-notify-paddingvar(--van-padding-xs) var(--van-padding-md)-
--van-notify-font-sizevar(--van-font-size-md)-
--van-notify-line-heightvar(--van-line-height-md)-
--van-notify-primary-background-colorvar(--van-primary-color)-
--van-notify-success-background-colorvar(--van-success-color)-
--van-notify-danger-background-colorvar(--van-danger-color)-
--van-notify-warning-background-colorvar(--van-warning-color)-
`,15),o=[l],h={__name:"README",setup(d,{expose:s}){return s({frontmatter:{}}),(c,r)=>(t(),a("div",e,o))}};export{h as default};