Skip to content

Notify 消息通知

介绍

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

函数调用

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

WARNING

因小程序无法动态挂载组件,使用时需要页面存在一个 Notify 组件,且函数调用方法需要在 onLoad 生命周期后调用。

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 });

单例使用

通过 v-model 控制通知是否展示,你也可以通过组件的 ref 获取实例,调用 open 方法打开通知。

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'spinner'
type通知类型NotifyType'default'
message通知内容string-
icon通知图标名称,同 icon 组件IconsName-
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关闭按钮图标名称IconsName'round-close-fill'
close-icon-size关闭按钮图标大小string | number-
z-index层级string | number2001+

NotifyItem Props

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

代替原始 Props

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

Notify Events

事件名说明回调参数
click点击时触发MouseEvent
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关闭按钮

赣ICP备2025061025号-1