Skip to content

Notify 消息通知

介绍

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

函数调用

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

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 属性,相同文案且相同类型的通知会合并为一条,并在右侧展示合并次数徽标。

html
<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: '相同文案会合并计数' });

单例使用

通过布尔 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是否合并相同文案且相同类型的通知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打开通知NotifyOpenOptionnumber
close关闭通知id?: number-

类型定义

组件导出以下类型定义:

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

赣ICP备2025061025号-1