Skip to content

FxMsg 消息提示

命令式 API,从顶部出现、自动消失、多条堆叠。不依赖任何 UI 框架。全局方法 app.config.globalProperties.$fxMsg

基础用法

从顶部出现,3 秒后消失。可用 placement 控制位置。

不同类型

用于展示 Success / Warning / Info / Error 等反馈。常用方法的 type 默认 infoprimary 在 ^(2.9.11) 加入。

朴素模式

plain 设为 true 时背景为白色。

可关闭

可以添加关闭按钮。默认不可手动关闭,设置 showClose 后可关。duration 默认 3000ms,设为 0 不自动消失。

使用 HTML 字符串

message 支持 HTML 字符串。

合并消息

合并相同内容的消息。

方位

控制消息出现的位置。默认顶部,可选 top / top-left / top-right / bottom / bottom-left / bottom-right

局部引入

ts
import { fxMsg } from '@fx/components'

可直接调用 fxMsg(options),同时注册了不同类型的方法如 fxMsg.success(options)。调用 fxMsg.closeAll() 可手动关闭所有消息。调用 fxMsg.closeAll(type?) 可按类型关闭。

API

Options

NameDescriptionTypeDefault
message消息文字string / VNode / () => VNode''
type消息类型'primary' | 'success' | 'warning' | 'info' | 'error'info
plain是否朴素booleanfalse
icon自定义图标组件,覆盖 typeComponent
dangerouslyUseHTMLStringmessage 是否作为 HTMLbooleanfalse
customClass自定义 classstring''
duration显示时长 ms(0 不自动关)number3000
showClose是否显示关闭按钮booleanfalse
onClose关闭回调() => void
offset距视口边缘偏移number16
placement消息出现方位'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right'top
appendTo挂载容器string / HTMLElementbody
max同方位同时显示的最大数量,超出则不再创建number
grouping相同内容的消息合并booleanfalse
repeatNum重复次数(配合 grouping)number1

Methods

fxMsg() 返回 { close },可手动关闭。

NameDescriptionType
close关闭消息() => void