Skip to content

Notification 通知

在页面一角显示通知信息,常用于系统推送、操作结果等场景。

基础用法

通过 ZcNotification 函数调用,传入标题和内容。

不同类型

通过 type 属性设置通知类型,支持 infosuccesswarningdanger

显示位置

通过 position 属性控制通知出现的位置。

自定义时长

通过 duration 控制通知显示时长,设置为 0 则不会自动关闭。

Notification API

Options

参数说明类型默认值
title通知标题string
message通知正文内容string
type通知类型info | success | warning | dangerinfo
duration显示时间(毫秒),0 为常驻number4500
showClose是否显示关闭按钮booleantrue
position通知显示位置top-right | top-left | bottom-right | bottom-lefttop-right
offset距离边界的偏移量(px)number16
onClose关闭时的回调函数() => void

Events

事件名说明回调参数
close通知关闭时触发

快捷方式

ZcNotification 提供以下快捷方法:

  • ZcNotification.info(options) - 信息通知
  • ZcNotification.success(options) - 成功通知
  • ZcNotification.warning(options) - 警告通知
  • ZcNotification.danger(options) - 错误通知

每个快捷方法均接受字符串或配置对象(不含 type 字段)。

导出

名称描述
ZcNotification通知函数,含类型快捷方法
ZcNotificationCloseAll关闭所有通知实例

注意事项

  • SSR 兼容性ZcNotification 依赖 document 对象,在 SSR 环境中调用需确保仅在客户端执行。
  • 自动关闭:默认 4.5 秒后自动关闭。设置 duration: 0 可实现手动关闭。
  • 位置管理:支持 top-righttop-leftbottom-rightbottom-left 四个方位,相同位置的通知会自动堆叠并计算偏移量。
  • 鼠标悬停:鼠标移入通知区域时会暂停自动关闭计时器,移出后恢复。

基于 MIT 许可发布