在 Element UI(针对 Vue 2)和 Element Plus(针对 Vue 3)中,Notification
通知组件通常不是作为一个可以直接在模板中使用的组件提供的,而是通过全局方法或服务来调用的。下面我将分别介绍在 Vue 2 的 Element UI 和 Vue 3 的 Element Plus 中如何使用 Notification
。
Vue 2 + Element UI
在 Vue 2 的 Element UI 中,你可以通过 $notify
方法来调用 Notification
。
方法
$notify(options)
:显示一个通知。
options 参数:
title
:标题。message
:消息内容。type
:通知类型,如success
、warning
、info
、error
。duration
:显示时间,单位为毫秒,默认值为 4500 毫秒。设置为 0 则不会自动关闭。offset
:距离屏幕顶部的偏移量。position
:自定义弹出位置,如top-right
、top-left
、bottom-right
、bottom-left
。closeButton
:是否显示关闭按钮。onClose