Skip to content

Notify 消息通知 ​

介绍 ​

在页面顶部/底部展示消息通知。

函数调用 ​

为了便于使用 Notify,提供了 showNotify、closeNotify 函数,用于显示和关闭 Notify,可设置标识指定一个 Notify 组件调用。

  • 可脱离 setup:showNotify / closeNotify 可在任意逻辑中直接调用(如工具函数、请求回调),无需在 setup 里先拿到实例。
  • 当前页实例:省略 name 时,会调用当前页面中已挂载的 Notify;传入 name 时匹配对应标识的实例。
  • 调用时机:组件尚未就绪时也可调用,会等待就绪后再打开,无需自行延后。

WARNING

因小程序无法动态挂载组件,使用时需要页面存在一个 Notify 组件。

html
<vd-notify name="page" />
ts
import { showNotify } from 'vital-design';

showNotify('提示内容');

// 指定一个 Notify 调用
showNotify({ name: 'page', message: '提示内容' });

基础用法 ​

通过设置 type 属性来设置提示类型,默认为 default。

html
<vd-notify name="page" />
ts
import { showNotify } from 'vital-design';

showNotify({ name: 'page', message: '文字提示' });
showNotify({ name: 'page', type: 'default', message: '默认提示' });
showNotify({ name: 'page', type: 'primary', message: '主要提示' });
showNotify({ name: 'page', type: 'success', message: '成功提示' });
showNotify({ name: 'page', type: 'warning', message: '警告提示' });
showNotify({ name: 'page', type: 'error', message: '失败提示' });

弹出位置 ​

通过设置 position 属性来设置弹出位置,默认为 top。

html
<vd-notify name="page" position="bottom" />
ts
import { showNotify } from 'vital-design';

showNotify({ name: 'page', message: '文字提示' });

关闭按钮 ​

通过设置 closeable 属性来设置是否显示关闭按钮,默认为 false。

html
<vd-notify name="page" />
ts
import { showNotify } from 'vital-design';

showNotify({ name: 'page', message: '文字提示', closeable: true });

// 不自动关闭通知
showNotify({ name: 'page', message: '文字提示', closeable: true, duration: 0 });

文案合并 ​

开启 grouping 后,相同文案且相同类型的通知会合并为一条,并在右侧展示合并次数徽标。

可在组件上全局开启,也可在单次 open / showNotify 中传入(会覆盖组件 props)。

html
<!-- 该 Notify 上所有 open 默认合并 -->
<vd-notify name="page" grouping />
ts
import { showNotify } from 'vital-design';

// 同 message + type 才会合并计数
showNotify({ name: 'page', type: 'primary', message: '相同文案会合并计数' });
showNotify({ name: 'page', type: 'primary', message: '相同文案会合并计数' });

// 未在组件上开启时,也可按次开启
showNotify({
  name: 'page',
  type: 'primary',
  message: '相同文案会合并计数',
  grouping: true,
});

单例使用 ​

通过布尔 v-model 控制一条声明式通知(与命令式队列共用容器,内部仍用列表管理)。内容 props 变化时会更新该条,而不会重复插入。

也可通过 ref 调用 open / close。需要完全自定义单条 UI 时,优先用下方的 notify-item。

html
<vd-notify v-model="show" message="测试通知消息" type="primary" />
<vd-notify ref="notifyRef" />
ts
const show = ref(false);
const notifyRef = shallowRef();

notifyRef.value.open({ type: 'primary', message: '测试通知消息' });

单通知项使用 ​

你可直接使用 notify-item 组件来显示一个通知项。

html
<vd-notify-item v-model="show" message="测试通知消息" type="primary" closeable />
ts
const show = ref(false);

API ​

Notify Props ​

参数说明类型默认值
v-model是否展示单条通知boolean-
name标识名称string-
type通知类型NotifyType'default'
message通知内容string-
icon通知图标名称,同 icon 组件IconName-
icon-size通知图标大小string | number-
duration展示时长,为 0 不自动关闭string | number3000
transition-duration动画时长TransitionDuration{ enter: 300, leave: 500 }
offset弹出偏移量string | number16
offset-navbar弹出偏移量是否添加导航栏高度booleantrue
offset-tabbar弹出偏移量是否添加标签栏高度booleantrue
position弹出位置'top' | 'bottom''top'
closeable是否显示关闭按钮booleanfalse
close-icon关闭按钮图标名称IconName'round-close-fill'
close-icon-size关闭按钮图标大小string | number-
z-index层级string | number2001+
grouping是否合并相同文案且相同类型的通知;也可在 open / showNotify 的 option 中按次传入booleanfalse

NotifyItem Props ​

参数说明类型默认值
v-model是否展示boolean-
type通知类型NotifyType'default'
message通知内容string-
icon通知图标名称,同 icon 组件IconName-
icon-size通知图标大小string | number-
duration展示时长,为 0 不自动关闭string | number0
count合并次数,大于 1 时展示徽标string | number1
transition弹出动画TransitionName'collapse-fade'
transition-duration动画时长TransitionDuration300
closeable是否显示关闭按钮booleanfalse
close-icon关闭按钮图标名称IconName'round-close-fill'
close-icon-size关闭按钮图标大小string | number-

代替原始 Props ​

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Notify Events ​

事件名说明回调参数
click点击时触发MouseEvent
update:model-value展示状态更新时触发boolean
click-item点击通知项时触发NotifyOnClickItemEvent
open打开时触发NotifyItem
opened打开动画结束时触发NotifyItem
close关闭时触发NotifyItem
closed关闭动画结束时触发NotifyItem

NotifyItem Events ​

事件名说明回调参数
click点击时触发MouseEvent
click-close点击关闭时触发MouseEvent
open打开时触发-
opened打开动画结束时触发-
close关闭时触发-
closed关闭动画结束时触发-

NotifyItem Slots ​

名称说明
icon图标
default消息
close关闭按钮

Notify Expose ​

方法名说明参数返回值
open打开通知;option 可覆盖组件上的内容类 props,另支持 groupingNotifyOpenOptionnumber
close关闭通知id?: number-

类型定义 ​

组件导出以下类型定义:

ts
import type {
  NotifyItem,
  NotifyOpenOption,
  NotifyOnClickItemEvent,
  NotifyInstance,
} from 'vital-design';

赣ICP备2025061025号-1