May 07, 2021 Vant
import Vue from 'vue';
import { Notify } from 'vant';
Vue.use(Notify);
Notify('通知内容');
The four notification types, primary, success, warning, and danger, are supported, defaulting to danger
// 主要通知
Notify({ type: 'primary', message: '通知内容' });
// 成功通知
Notify({ type: 'success', message: '通知内容' });
// 危险通知
Notify({ type: 'danger', message: '通知内容' });
// 警告通知
Notify({ type: 'warning', message: '通知内容' });
Customize the color and presentation time of message notifications
Notify({
message: '自定义颜色',
color: '#ad0000',
background: '#ffe1e1'
});
Notify({
message: '自定义时长',
duration: 1000
});
When the Notify component is introduced, the method is automatically mounted on Vue'$notify, making it easy to call within the component.
export default {
mounted() {
this.$notify('提示文案');
}
}
The method name | Description | Parameters | Returns a value |
---|---|---|---|
Notify | Show tips |
options | message
|
Notify instance |
Notify.clear | Turn off the prompt | - |
void
|
Notify.setDefaultOptions | Modify the default configuration to take effect for all Notify |
options
|
void
|
Notify.resetDefaultOptions | Reset the default configuration to take effect for all Notify | - |
void
|
Parameters | Description | Type | The default |
---|---|---|---|
type
v2.1.6
|
Type, the optional value
primary
success
warning
|
string |
danger
|
message |
Show the document, support through
\n
line
|
string | - |
duration | The presentation time (ms), when the value is 0, notify does not disappear | number | string |
3000
|
color | The font color | string |
white
|
background | The background color | string | - |
className | Custom class name | any | - |
onClick | The callback function when clicked | Function | - |
onOpened | A fully displayed callback function | Function | - |
onClose | The callback function when closed | Function | - |