Skip to content

Message 消息提示

常用于主动操作后的反馈提示。与 Notification 的区别是后者更多用于系统级通知的被动提醒。

基础用法

从顶部出现,3 秒后自动消失。

不同状态

用来显示「成功、警告、消息、错误」类的操作反馈。

可关闭

可以添加关闭按钮。

文字居中

使用 center 属性让文字水平居中。

使用 HTML 片段

dangerouslyUseHTMLString 属性设置为 true,message 就会被当作 HTML 片段处理。

消息合并

如果设置了 groupingtrue,那么内容相同的消息将合并显示。

朴素模式 (Unique Feature)

设置为 plain 模式,背景变为白色,更清爽。

自定义位置 (Unique Feature)

可以通过 position 属性设置消息出现的位置。支持 top-right, top-left, bottom-right, bottom-left, top-center (默认), bottom-center

无图标 (Unique Feature)

可以通过 showIcon 属性设置为 false 来隐藏图标。

API

Message Options

属性名说明类型默认值
message消息文字string / VNode''
type主题'success' / 'warning' / 'info' / 'error''info'
icon自定义图标string / Component''
dangerouslyUseHTMLString是否将 message 属性作为 HTML 片段处理booleanfalse
customClass自定义类名string''
duration显示时间, 毫秒。设为 0 则不会自动关闭number3000
showClose是否显示关闭按钮booleanfalse
center文字是否居中booleanfalse
onClose关闭时的回调函数, 参数为被关闭的 message 实例function-
offsetMessage 距离窗口顶部的偏移量number16
appendTo设置 Message 的根元素HTMLElement / stringdocument.body
grouping是否合并内容相同的消息,不支持 VNodebooleanfalse
plain是否开启朴素模式booleanfalse
position自定义位置'top-right' / 'top-left' / 'bottom-right' / 'bottom-left' / 'top-center' / 'bottom-center''top-center'
showIcon是否显示图标booleantrue

Message Methods

方法名说明参数
close关闭当前的 Message-
closeAll关闭所有 Messagetype?: MessageType