FxMsg 消息提示
命令式 API,从顶部出现、自动消失、多条堆叠。不依赖任何 UI 框架。全局方法 app.config.globalProperties.$fxMsg。
基础用法
从顶部出现,3 秒后消失。可用 placement 控制位置。
不同类型
用于展示 Success / Warning / Info / Error 等反馈。常用方法的 type 默认 info;primary 在 ^(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
| Name | Description | Type | Default |
|---|---|---|---|
| message | 消息文字 | string / VNode / () => VNode | '' |
| type | 消息类型 | 'primary' | 'success' | 'warning' | 'info' | 'error' | info |
| plain | 是否朴素 | boolean | false |
| icon | 自定义图标组件,覆盖 type | Component | — |
| dangerouslyUseHTMLString | message 是否作为 HTML | boolean | false |
| customClass | 自定义 class | string | '' |
| duration | 显示时长 ms(0 不自动关) | number | 3000 |
| showClose | 是否显示关闭按钮 | boolean | false |
| onClose | 关闭回调 | () => void | — |
| offset | 距视口边缘偏移 | number | 16 |
| placement | 消息出现方位 | 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | top |
| appendTo | 挂载容器 | string / HTMLElement | body |
| max | 同方位同时显示的最大数量,超出则不再创建 | number | — |
| grouping | 相同内容的消息合并 | boolean | false |
| repeatNum | 重复次数(配合 grouping) | number | 1 |
Methods
fxMsg() 返回 { close },可手动关闭。
| Name | Description | Type |
|---|---|---|
| close | 关闭消息 | () => void |
