对话框

何时使用

需要用户处理事务,又不希望跳转页面以致打断工作流程时,可以使用 Modal 在当前页面正中打开一个浮层,承载相应的操作。

另外当需要一个简洁的确认框询问用户时,可以使用 Modal.confirm() 等语法糖方法。

基础用法

  • 示例:
点击查看代码
<template>
  <z-button type="primary" @click="showModal">Open Modal</z-button>
  <z-modal v-model:visible="visible" title="Basic Modal" @ok="handleOk">
    <p>Some contents...</p>
    <p>Some contents...</p>
    <p>Some contents...</p>
  </z-modal>
</template>
<script>
  import { defineComponent, ref } from 'vue'
  export default defineComponent({
    setup() {
      const visible = ref(false)
      const showModal=()=>{
        visible.value=true
      }
      return {
        visible,
        showModal
      }
    }
  })
</script>
    

参数

参数说明类型默认值
afterCloseModal 完全关闭后的回调function
bodyStyleModal body 样式object{}
cancelButtonPropscancel 按钮 props
cancelText取消按钮文字string | slot取消
centered垂直居中展示 Modalbooleanfalse
closable是否显示右上角的关闭按钮booleantrue
closeIcon自定义关闭图标slot
confirmLoading确定按钮 loadingboolean
destroyOnClose关闭时销毁 Modal 里的子元素booleanfalse
dialogClass可用于设置浮层的类名string
dialogStyle可用于设置浮层的样式,调整浮层位置等object
footer底部内容,当不需要默认底部按钮时,可以设为 :footer="null"string|slot确定取消按钮
forceRender强制渲染 Modalbooleanfalse
getContainer指定 Modal 挂载的 HTML 节点(instance): HTMLElement() => document.body
keyboard是否支持键盘 esc 关闭booleantrue
mask是否展示遮罩booleantrue
maskClosable点击蒙层是否允许关闭booleanture
maskStyle遮罩样式object{}
okButtonPropsok 按钮 props
okText确认按钮文字string|slot确认
okType确认按钮类型stringprimary
title标题boolean
visible(v-model)对话框是否可见boolean
width宽度string|number520
wrapClassName对话框外层容器的类名string
zIndex设置 Modal 的 z-indexnumber1000

事件

事件说明回调参数
cancel点击遮罩层或右上角叉或取消按钮的回调function(e)
ok点击确定回调function(e)
Last Updated:
Contributors: jixuanyu