1.0.1 • Published 2 years ago

ele-easy-toast v1.0.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

EleEasyToast

对elementUI的Message和Notification的节流二次封装

// main.js
import Vue from 'vue';
/** **/
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import EasyToast from 'ele-easy-toast';

Vue.use(ElementUI);
// 切记要放在'Vue.use(ElementUI)'后面
Vue.use(EasyToast);
/** **/

Message 消息提示

全局方法

EasyToast 为 Vue.prototype 添加了全局方法 $message。因此在 vue instance 中可以采用本页面中的方式调用 Message

单独引用

单独引入 Message

import { Message } from 'ele-easy-toast';

此时调用方法为 Message(options)。我们也为每个 type 定义了各自的方法,如 Message.success(options)。并且可以调用 Message.closeAll() 手动关闭所有实例。

Options

参数说明类型可选值默认值
message消息文字string / VNode
type主题stringsuccess/warning/info/errorinfo
iconClass自定义图标的类名,会覆盖 typestring
dangerouslyUseHTMLString是否将 message 属性作为 HTML 片段处理booleanfalse
customClass自定义类名string
duration显示时间, 毫秒。设为 0 则不会自动关闭number3000
showClose是否显示关闭按钮booleanfalse
center文字是否居中booleanfalse
onClose关闭时的回调函数, 参数为被关闭的 message 实例function
offsetMessage 距离窗口顶部的偏移量number20

方法

调用 Messagethis.$message 会返回当前 Message 的实例。如果需要手动关闭实例,可以调用它的 close 方法。

方法名说明
close关闭当前的 Message

Notification 通知

全局方法

EasyToast 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。

单独引用

单独引入 Notification:

import { Notification } from 'ele-easy-toast';

此时调用方法为 Notification(options)。我们也为每个 type 定义了各自的方法,如 Notification.success(options)。并且可以调用 Notification.closeAll() 手动关闭所有实例。

Options

参数说明类型可选值默认值
title标题string
message说明文字string/Vue.VNode
dangerouslyUseHTMLString是否将 message 属性作为 HTML 片段处理booleanfalse
type主题样式,如果不在可选值内将被忽略stringsuccess/warning/info/error
iconClass自定义图标的类名。若设置了 type,则 iconClass 会被覆盖string
customClass自定义类名string
duration显示时间, 毫秒。设为 0 则不会自动关闭number4500
position自定义弹出位置stringtop-right/top-left/bottom-right/bottom-lefttop-right
showClose是否显示关闭按钮booleantrue
onClose关闭时的回调函数function
onClick点击 Notification 时的回调函数function
offset偏移的距离,在同一时刻,所有的 Notification 实例应当具有一个相同的偏移量number0

方法

调用 Notificationthis.$notify 会返回当前 Notification 的实例。如果需要手动关闭实例,可以调用它的 close 方法。

方法名说明
close关闭当前的 Notification

参考链接:

https://element.eleme.cn/#/zh-CN/component/notification

https://element.eleme.cn/#/zh-CN/component/message

1.0.1

2 years ago

1.0.0

2 years ago