Notification 通知提醒框
全局展示通知提醒信息
何时使用
- 需要全局通知提醒时。
导入
基础用法
全局展示通知提醒信息,支持多种位置、类型、自动关闭和进度条。需要在 App 根组件挂载一次 NotificationContainer。
带图标的通知
通过 success / info / warning / error 方法展示不同类型的通知。
自定义位置
通过 placement 设置弹出位置。
进度条 + 不自动关闭
通过 key 更新
API
useNotification()
返回一个对象,包含以下方法:
| 方法 | 说明 | 返回值 |
|---|---|---|
| open(options) | 打开通知 | string (id) |
| success(options) | 成功通知 | string |
| error(options) | 错误通知 | string |
| info(options) | 信息通知 | string |
| warning(options) | 警告通知 | string |
| close(id) | 关闭指定通知 | void |
| destroy(id?) | 销毁通知(不传 id 销毁全部) | void |
| notifications | 通知列表(ref) | Ref<NotificationItem[]> |
NotificationOptions
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| key | 唯一标识(用于更新) | string | 自动生成 |
| title | 标题 | string | - |
| description | 内容 | string | - |
| type | 类型 | "info" | "success" | "warning" | "error" | "default" | default |
| duration | 自动关闭延时(秒),0/false 不关闭 | number | false | 4.5 |
| showProgress | 显示进度条 | boolean | false |
| pauseOnHover | 悬停暂停 | boolean | true |
| placement | 弹出位置 | NotificationPlacement | topRight |
| closable | 关闭按钮 | boolean | true |
| onClick | 点击回调 | () => void | - |
| onClose | 关闭回调 | () => void | - |
NotificationPlacement
top bottom topLeft topRight bottomLeft bottomRight
组件
| 组件 | 说明 |
|---|---|
| NotificationContainer | 容器组件,需在 App 根组件挂载一次 |
| NotificationItem | 单条通知卡片 |
