Skip to content

Dialog ​

简易介绍 ​

dialog对话框组件,用于在页面中显示模态对话框。
可以使用<MYDialog></MYDialog>或者<MYDialog />来实现一个对话框。

基础用法 ​

使用v-model控制对话框的显示与隐藏。

代码演示
展开代码

自定义尺寸 ​

使用width和height属性可以自定义对话框的尺寸。

代码演示
展开代码

自定义颜色 ​

使用backgroundColor、borderColor和textColor属性可以自定义对话框的颜色。

代码演示
展开代码

禁用遮罩层关闭 ​

使用closeOnClickModal属性可以禁用点击遮罩层关闭对话框。

代码演示
展开代码

禁用ESC关闭 ​

使用closeOnPressEscape属性可以禁用ESC键关闭对话框。

代码演示
展开代码

溢出控制 ​

使用overflow属性可以控制对话框内容的溢出行为。

代码演示
展开代码

自定义头部和底部 ​

使用header和footer插槽可以自定义对话框的头部和底部。

代码演示
展开代码

事件监听 ​

对话框提供了open和close事件用于监听打开和关闭状态。

代码演示
展开代码

组合使用 ​

最后,实现个多种api组合使用实现个完整的对话框:

代码演示
展开代码

API 参考 ​

Props ​

参数说明类型可选值默认值
modelValue是否显示对话框boolean—false
title对话框标题string—''
width对话框宽度string | number—400
height对话框高度string | number—200
closeOnClickModal点击遮罩层关闭boolean—true
closeOnPressEscape按ESC键关闭boolean—true
backgroundColor背景色string—''
borderColor边框颜色string—''
textColor文字颜色string—''
overflow溢出控制boolean—false

Events ​

事件名说明参数
update:modelValue对话框显示状态更新value: boolean
open对话框打开时触发—
close对话框关闭时触发—

Slots ​

名称说明
default对话框主体内容
header自定义头部
footer自定义底部

类型定义 ​

typescript
interface DialogProps {
  modelValue?: boolean;
  title?: string;
  width?: string | number;
  height?: string | number;
  closeOnClickModal?: boolean;
  closeOnPressEscape?: boolean;
  backgroundColor?: string;
  borderColor?: string;
  textColor?: string;
  overflow?: boolean;
}

interface DialogEmits {
  (e: 'update:modelValue', value: boolean): void;
  (e: 'open'): void;
  (e: 'close'): void;
}

基于 MIT 协议