Vant Notify 消息提示

引入

import Vue from vue;
import { Notify } from vant;

Vue.use(Notify);

代码演示

基础用法

Notify(通知内容);

通知类型

支持primary、success、warning、danger四种通知类型,默认为danger

// 主要通知
Notify({ type: primary, message: 通知内容 });

// 成功通知
Notify({ type: success, message: 通知内容 });

// 危险通知
Notify({ type: danger, message: 通知内容 });

// 警告通知
Notify({ type: warning, message: 通知内容 });

自定义通知

自定义消息通知的颜色和展示时长

Notify({
  message: 自定义颜色,
  color: #ad0000,
  background: #ffe1e1
});

Notify({
  message: 自定义时长,
  duration: 1000
});

组件内调用

引入 Notify 组件后,会自动在 Vue 的 prototype 上挂载 $notify 方法,便于在组件内调用。

export default {
  mounted() {
    this.$notify(提示文案);
  }
}

API

方法

方法名说明参数返回值
Notify展示提示options | messagenotify 实例
Notify.clear关闭提示void
Notify.setDefaultOptions修改默认配置,对所有 Notify 生效optionsvoid
Notify.resetDefaultOptions重置默认配置,对所有 Notify 生效void

Options

参数说明类型默认值
type v2.1.6类型,可选值为 primary success warningstringdanger
message展示文案,支持通过
换行
string
duration展示时长(ms),值为 0 时,notify 不会消失number | string3000
color字体颜色stringwhite
background背景颜色string
className自定义类名any
onClick点击时的回调函数Function
onOpened完全展示后的回调函数Function
onClose关闭时的回调函数Function

实例演示

作者:唐伯虎点蚊香,如若转载,请注明出处:https://www.web176.com/vant/15515.html

(0)
打赏 支付宝 支付宝 微信 微信
唐伯虎点蚊香的头像唐伯虎点蚊香
上一篇 2023年4月14日
下一篇 2023年4月14日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注