Notification 通知提醒框

全局展示通知提醒信息

何时使用

  • 需要全局通知提醒时。

导入

import { NotificationContainer, useNotification } from "@reglow/reui";

基础用法

全局展示通知提醒信息,支持多种位置、类型、自动关闭和进度条。需要在 App 根组件挂载一次 NotificationContainer

<script setup lang="ts">
import {
  NotificationContainer,
  useNotification,
} from "@reglow/reui";
import { Button } from "@reglow/reui";

const notify = useNotification();

function showNotification() {
  notify.open({
    title: "通知标题",
    description: "这是一条通知内容",
  });
}
</script>

<template>
  <Button @click="showNotification">显示通知</Button>
  <NotificationContainer />
</template>

带图标的通知

通过 success / info / warning / error 方法展示不同类型的通知。

<script setup lang="ts">
import { useNotification } from "@reglow/reui";

const notify = useNotification();

// success / info / warning / error
notify.success({ title: "操作成功", description: "数据已保存" });
notify.error({ title: "操作失败", description: "网络错误" });
notify.info({ title: "提示", description: "请注意此项" });
notify.warning({ title: "警告", description: "操作不可逆" });
</script>

自定义位置

通过 placement 设置弹出位置。

notify.open({
  title: "位置通知",
  description: "从左下角弹出",
  placement: "bottomLeft",
});

进度条 + 不自动关闭

// 带进度条
notify.info({
  title: "处理中",
  description: "请稍候...",
  showProgress: true,
  duration: 10,
});

// 不自动关闭
notify.warning({
  title: "需要确认",
  description: "请确认操作",
  duration: 0,
});

通过 key 更新

notify.open({ key: "loading", title: "加载中..." });
setTimeout(() => {
  notify.open({ key: "loading", title: "完成", type: "success" });
}, 1000);

// 销毁所有
notify.destroy();

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 | false4.5
showProgress显示进度条booleanfalse
pauseOnHover悬停暂停booleantrue
placement弹出位置NotificationPlacementtopRight
closable关闭按钮booleantrue
onClick点击回调() => void-
onClose关闭回调() => void-

NotificationPlacement

top bottom topLeft topRight bottomLeft bottomRight

组件

组件说明
NotificationContainer容器组件,需在 App 根组件挂载一次
NotificationItem单条通知卡片