Element-Ui组件(三十八)Dialog 对话框

Element-Ui组件(三十八)Dialog 对话框

本文来源于Element官方文档:

http://element-cn.eleme.io/#/zh-CN/component/dialog

基础用法

普通对话框

<el-button type="text" @click="dialogVisible = true">点击打开 Dialogel-button>

<el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
  <span>这是一段信息span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定el-button>
  span>
el-dialog>

<script>
  export default {
    data() {
      return {
        dialogVisible: false
      };
    },
    methods: {
      handleClose(done) {
        this.$confirm('确认关闭?')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      }
    }
  };
script>

自定义对话框



<el-button type="text" @click="dialogTableVisible = true">打开嵌套表格的 Dialogel-button>

<el-dialog title="收货地址" :visible.sync="dialogTableVisible">
  <el-table :data="gridData">
    <el-table-column property="date" label="日期" width="150">el-table-column>
    <el-table-column property="name" label="姓名" width="200">el-table-column>
    <el-table-column property="address" label="地址">el-table-column>
  el-table>
el-dialog>


<el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialogel-button>

<el-dialog title="收货地址" :visible.sync="dialogFormVisible">
  <el-form :model="form">
    <el-form-item label="活动名称" :label-width="formLabelWidth">
      <el-input v-model="form.name" auto-complete="off">el-input>
    el-form-item>
    <el-form-item label="活动区域" :label-width="formLabelWidth">
      <el-select v-model="form.region" placeholder="请选择活动区域">
        <el-option label="区域一" value="shanghai">el-option>
        <el-option label="区域二" value="beijing">el-option>
      el-select>
    el-form-item>
  el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消el-button>
    <el-button type="primary" @click="dialogFormVisible = false">确 定el-button>
  div>
el-dialog>

嵌套对话框

<el-button type="text" @click="outerVisible = true">点击打开外层 Dialog</el-button>

  <el-dialog title="外层 Dialog" :visible.sync="outerVisible">
    <el-dialog
      width="30%"
      title="内层 Dialog"
      :visible.sync="innerVisible"
      append-to-body>
    </el-dialog>
    <div slot="footer" class="dialog-footer">
      <el-button @click="outerVisible = false">取 消</el-button>
      <el-button type="primary" @click="innerVisible = true">打开内层 Dialog</el-button>
    </div>
  </el-dialog>

Steps Attributes:

参数 类型 说明 可选值 默认值
visible 是否显示 Dialog,支持 .sync 修饰符 boolean false
title Dialog 的标题,也可通过具名 slot (见下表)传入 string
width Dialog 的宽度 string 50%
fullscreen 是否为全屏 Dialog boolean false
top Dialog CSS 中的 margin-top 值 string 15vh
modal 是否需要遮罩层 boolean true
modal-append-to-body 遮罩层是否插入至 body 元素上,若为 false,则遮罩层会插入至 Dialog 的父元素上 boolean true
append-to-body Dialog 自身是否插入至 body 元素上。嵌套的 Dialog 必须指定该属性并赋值为 true boolean false
lock-scroll 是否在 Dialog 出现时将 body 滚动锁定 boolean true
custom-class Dialog 的自定义类名 string
close-on-click-modal 是否可以通过点击 modal 关闭 Dialog boolean true
close-on-press-escape 是否可以通过按下 ESC 关闭 Dialog boolean true
show-close 是否显示关闭按钮 boolean true
before-close 关闭前的回调,会暂停 Dialog 的关闭 function(done),done 用于关闭 Dialog
center 是否对头部和底部采用居中布局 boolean false

Step Slot

name 说明
Dialog 的内容
title Dialog 标题区的内容
footer Dialog 按钮操作区的内容

Events

事件名称 说明 回调参数
close Dialog 关闭的回调
open Dialog 打开的回调

你可能感兴趣的:(Vue.js)