Modal 模态对话框
模态对话框,用于确认、提示或展示内容
何时使用
- 需要模态窗口承载内容时。
导入
基础用法
更多示例
自定义头部和页脚
通过 header 和 footer 自定义。
尺寸
通过 size 设置宽度尺寸。
全屏 Modal
设置 fullScreen 开启全屏对话框。
确认按钮 loading
通过 confirmLoading 显示确认按钮 loading 状态。
命令式调用
使用 ModalMethods 进行命令式调用。
命令式调用(异步确认)
onOk 返回 Promise 时,确认按钮自动显示 loading。
Hooks 用法
API
Modal Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| visible (v-model) | 是否可见 | boolean | false |
| title | 标题 | VNode | string | - |
| content | 内容(命令式调用用) | VNode | string | - |
| type | 类型 | info | success | error | warning | confirm | confirm |
| icon | 自定义图标 | VNode | - |
| size | 尺寸 | small | medium | large | full-width | small |
| width | 宽度 | number | string | - |
| height | 高度 | number | string | - |
| centered | 是否居中显示 | boolean | false |
| fullScreen | 全屏 | boolean | false |
| closable | 显示关闭按钮 | boolean | true |
| closeIcon | 自定义关闭图标 | VNode | - |
| closeOnEsc | ESC 关闭 | boolean | true |
| mask | 显示遮罩 | boolean | true |
| maskClosable | 点击遮罩关闭 | boolean | true |
| maskStyle | 遮罩样式 | CSSProperties | - |
| bodyStyle | 内容样式 | CSSProperties | - |
| style | 自定义样式 | CSSProperties | - |
| okText | 确认按钮文字 | string | 确定 |
| cancelText | 取消按钮文字 | string | 取消 |
| okType | 确认按钮类型 | primary | secondary | tertiary | warning | danger | primary |
| okButtonProps | 确认按钮属性 | Record<string, any> | - |
| cancelButtonProps | 取消按钮属性 | Record<string, any> | - |
| hasCancel | 是否显示取消按钮 | boolean | true |
| footer | 自定义页脚 | VNode | null | - |
| header | 自定义头部 | VNode | null | - |
| footerFill | 底部按钮撑满 | boolean | false |
| confirmLoading | 确认按钮 loading | boolean | false |
| motion | 动画效果 | boolean | true |
| zIndex | z-index | number | 1000 |
| class | 附加类名 | string | - |
Modal Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| ok | 点击确认 | (e: MouseEvent) |
| cancel | 点击取消 | (e: MouseEvent) |
| afterClose | 完全关闭后 | () |
Modal Slots
| 名称 | 说明 |
|---|---|
| default | 内容 |
| title | 标题 |
| header | 头部 |
| footer | 页脚 |
| closeIcon | 关闭图标 |
ModalMethods
| 方法 | 说明 |
|---|---|
ModalMethods.info(config) | 信息提示 |
ModalMethods.success(config) | 成功提示 |
ModalMethods.error(config) | 错误提示 |
ModalMethods.warning(config) | 警告提示 |
ModalMethods.confirm(config) | 确认对话框 |
返回 { destroy(), update(config) }。
ModalConfig
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| title | 标题 | string | VNode | - |
| content | 内容 | string | VNode | - |
| type | 类型 | info | success | error | warning | confirm | confirm |
| icon | 自定义图标 | VNode | - |
| okText | 确认文字 | string | - |
| cancelText | 取消文字 | string | - |
| okType | 确认按钮类型 | string | primary |
| okButtonProps | 确认按钮属性 | Record<string, any> | - |
| cancelButtonProps | 取消按钮属性 | Record<string, any> | - |
| hasCancel | 显示取消按钮 | boolean | - |
| centered | 居中显示 | boolean | false |
| closable | 显示关闭按钮 | boolean | true |
| maskClosable | 点击遮罩关闭 | boolean | true |
| onOk | 确认回调(返回 Promise 自动 loading) | (e) => void | Promise<void> | - |
| onCancel | 取消回调 | (e) => void | Promise<void> | - |
| afterClose | 关闭后回调 | () => void | - |
尺寸对照
| size | 宽度 |
|---|---|
small | 448px |
medium | 684px |
large | 920px |
full-width | calc(100vw - 64px) |
类型对照
| type | 图标 | 说明 |
|---|---|---|
info | 蓝色信息 | 信息提示 |
success | 绿色对勾 | 成功提示 |
error | 红色错误 | 错误提示 |
warning | 黄色警告 | 警告提示 |
confirm | 蓝色问号 | 确认对话框 |
