悬浮出现在页面右上角,显示全局的通知提醒消息。
适用性广泛的通知栏
带有 icon,常用来显示「成功、警告、消息、错误」类的系统消息。
让 Notification 偏移一些位置。
你可以在导入 Notification
组件之后, 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。
import Notification from 'vue-multiple-notification'
this.$notify(options)
this.$notify.info(options)
this.$notify.success(options)
this.$notify.warning(options)
this.$notify.error(options)
this.$notify.closeAll()
单独引入 Notification
:
import Vue from 'vue'
import Notification from 'vue-multiple-notification'
Vue.prototype.$notify = Notification
Notification(options)
。我们也为每个 type
定义了各自的方法,如 Notification.success(options)
。 并且可以调用 Notification.closeAll()
手动关闭所有实例。
Notification(options)
Notification.info(options)
Notification.success(options)
Notification.warning(options)
Notification.error(options)
Notification.closeAll()
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
zIndex (新增) | 层级 | number | — | 2000 |
title | 标题 | string | — | — |
message | 说明文字 | string / VNode | — | — |
type | 主题样式,如果不在可选值内将被忽略 | string | success/warning/info/error | — |
iconClass | 自定义图标的类名。若设置了 type,则 iconClass 会被覆盖 | string | — | — |
customClass | 自定义类名 | string | — | — |
duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 4500 |
showClose | 是否显示关闭按钮 | boolean | — | true |
onClose | 关闭时的回调函数, 参数为被关闭的 notification 实例 | function | — | — |
onClick | 点击 Notification 时的回调函数, 参数为被关闭的 notification 实例 | function | — | — |
offset | 偏移的距离,在同一时刻,所有的 Notification 实例应当具有一个自身的偏移量 | number | — | 0 |
sameOffset (新增) | 所有的 Notification 实例是否应当具有一个相同的偏移量 | boolean | — | false |
调用 Notification
或 this.$notify
会返回当前 Notification
的实例。
如果需要手动关闭实例,可以调用它的 close
方法。
方法名 | 说明 |
---|---|
close | 关闭当前的 Notification |
调用 Notification.config(options)
来进行全局配置。
Notification.config({
duration: 3000,
zIndex: 2000
})
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
duration | 显示时间, 毫秒。设为 0 则不会自动关闭,优先级低于局部配置 | number | — | — |
zIndex | 层级,优先级低于局部配置 | number | — | — |
示例使用详情请参考:(https://github.com/savoygu/vue-demonstration)