Skip to content

Modal 对话框

在保留当前页面状态的情况下,弹出对话框。

基础用法

vue
<template>
  <x-button @click="visible = true">打开对话框</x-button>
  <x-modal v-model="visible" title="提示">
    <p>这是一段内容</p>
  </x-modal>
</template>

<script setup>
import { ref } from 'vue'
const visible = ref(false)
</script>

自定义内容

对话框的内容可以是任何组件或内容。

vue
<template>
  <x-modal v-model="visible" title="表单">
    <x-input v-model="form.name" placeholder="请输入姓名" />
  </x-modal>
</template>

API

Props

属性说明类型默认值
modelValue是否显示对话框booleanfalse
title对话框标题string
width对话框宽度string | number'50%'
top对话框 CSS 中的 top 值string'15vh'
modal是否显示遮罩层booleantrue
closeOnClickModal是否可以通过点击遮罩层关闭对话框booleantrue
closeOnPressEscape是否可以通过按下 ESC 关闭对话框booleantrue
showClose是否显示关闭按钮booleantrue
center是否对齐标题和底部居中booleanfalse
destroyOnClose关闭时销毁元素booleanfalse

Events

事件名说明回调参数
update:modelValue值改变时触发(value: boolean)
open打开时触发
close关闭时触发

基于 MIT 许可发布