import{o as t,a,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=n(`
The display message prompt is at the top of the page, and supports two methods: function call and component call.
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);
Notify('Notify Message');
Notify({ type: 'primary', message: 'Notify Message' });
Notify({ type: 'success', message: 'Notify Message' });
Notify({ type: 'danger', message: 'Notify Message' });
Notify({ type: 'warning', message: 'Notify Message' });
Notify({
message: 'Custom Color',
color: '#ad0000',
background: '#ffe1e1',
});
Notify({
message: 'Custom Position',
position: 'bottom',
});
Notify({
message: 'Custom Duration',
duration: 1000,
});
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');
},
};
<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,
};
},
};
Methods | Attribute | Return value | Description |
---|---|---|---|
Notify | options | message | notify instance | Show notify |
Notify.clear | - | void | Close notify |
Notify.setDefaultOptions | options | void | Set default options of all notifies |
Notify.resetDefaultOptions | - | void | Reset default options of all notifies |
Attribute | Description | Type | Default |
---|---|---|---|
type | Can be set to primary success warning | NotifyType | danger |
message | Message | string | - |
duration | Duration(ms), won't disappear if value is 0 | number | string | 3000 |
position v3.4.0 | Position, can be set to bottom | NotifyPosition | top |
color | Message color | string | white |
background | Background color | string | - |
className | Custom className | string | Array | object | - |
lockScroll v3.0.7 | Whether to lock background scroll | boolean | false |
onClick | Callback function after click | (event: MouseEvent) => void | - |
onOpened | Callback function after opened | () => void | - |
onClose | Callback function after close | () => void | - |
The component exports the following type definitions:
import type {
NotifyType,
NotifyProps,
NotifyOptions,
NotifyPosition,
} from 'vant';
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
Name | Default Value | Description |
---|---|---|
--van-notify-text-color | var(--van-white) | - |
--van-notify-padding | var(--van-padding-xs) var(--van-padding-md) | - |
--van-notify-font-size | var(--van-font-size-md) | - |
--van-notify-line-height | var(--van-line-height-md) | - |
--van-notify-primary-background-color | var(--van-primary-color) | - |
--van-notify-success-background-color | var(--van-success-color) | - |
--van-notify-danger-background-color | var(--van-danger-color) | - |
--van-notify-warning-background-color | var(--van-warning-color) | - |