Categories: Vant 教程

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 | message notify 实例
Notify.clear 关闭提示 void
Notify.setDefaultOptions 修改默认配置,对所有 Notify 生效 options void
Notify.resetDefaultOptions 重置默认配置,对所有 Notify 生效 void

Options

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

实例演示

唐伯虎点蚊香

前端小白,想各位学习!

Share
Published by
唐伯虎点蚊香

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

6 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

4 周 ago