element dialog源码

摘要:
this.fullscreen){style.marginTop=this.top;如果{style.width=this.width;}}returnstyle;},方法:{//我还没有找到这个。getMigratingConfig(){return{props:{'size':“sizeisremoved.”}};}//单击对话框本身handleWrapperClick(){if(!
<template>
  <transition
    name="dialog-fade"
    @after-enter="afterEnter"
    @after-leave="afterLeave">
    <div class="el-dialog__wrapper" v-show="visible" @click.self="handleWrapperClick">
      <div
        role="dialog"
        aria-modal="true"
        :aria-label="title || 'dialog'"
        class="el-dialog"
        :class="[{ 'is-fullscreen': fullscreen, 'el-dialog--center': center }, customClass]"
        ref="dialog"
        :style="style">
        <div class="el-dialog__header">
          <slot name="title">
            <span class="el-dialog__title">{{ title }}</span>
          </slot>
          <button
            type="button"
            class="el-dialog__headerbtn"
            aria-label="Close"
            v-if="showClose"
            @click="handleClose">
            <i class="el-dialog__close el-icon el-icon-close"></i>
          </button>
        </div>
        <div class="el-dialog__body" v-if="rendered"><slot></slot></div>
        <div class="el-dialog__footer" v-if="$slots.footer">
          <slot name="footer"></slot>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
  import Popup from 'element-ui/src/utils/popup';
  import Migrating from 'element-ui/src/mixins/migrating';
  import emitter from 'element-ui/src/mixins/emitter';

  export default {
    name: 'ElDialog',

    mixins: [Popup, emitter, Migrating],

    props: {
      // Dialog 的标题,也可通过具名 slot (见下表)传入
      title: {
        type: String,
        default: ''
      },
      // modal    是否需要遮罩层
      modal: {
        type: Boolean,
        default: true
      },
      // 遮罩层是否插入至 body 元素上,若为 false,则遮罩层会插入至 Dialog 的父元素上
      modalAppendToBody: {
        type: Boolean,
        default: true
      },
      // Dialog 自身是否插入至 body 元素上。嵌套的 Dialog 必须指定该属性并赋值为 true
      appendToBody: {
        type: Boolean,
        default: false
      },
      // lock-scroll    是否在 Dialog 出现时将 body 滚动锁定
      lockScroll: {
        type: Boolean,
        default: true
      },
      // close-on-click-modal    是否可以通过点击 modal 关闭 Dialog
      closeOnClickModal: {
        type: Boolean,
        default: true
      },
      // close-on-press-escape    是否可以通过按下 ESC 关闭 Dialog    
      closeOnPressEscape: {
        type: Boolean,
        default: true
      },
      // show-close    是否显示关闭按钮
      showClose: {
        type: Boolean,
        default: true
      },
      // width    Dialog 的宽度
       String,
      // fullscreen    是否为全屏 Dialog 
      fullscreen: Boolean,
      // custom-class    Dialog 的自定义类名
      customClass: {
        type: String,
        default: ''
      },
      // top    Dialog CSS 中的 margin-top 值
      top: {
        type: String,
        default: '15vh'
      },
      // before-close    关闭前的回调,会暂停 Dialog 的关闭
      beforeClose: Function,
      // center    是否对头部和底部采用居中布局
      center: {
        type: Boolean,
        default: false
      }
    },

    data() {
      return {
        closed: false
      };
    },

    watch: {
      // 是否显示 Dialog,支持 .sync 修饰符
      visible(val) {
        if (val) {
          this.closed = false;
          this.$emit('open');
          this.$el.addEventListener('scroll', this.updatePopper);
          this.$nextTick(() => {
            this.$refs.dialog.scrollTop = 0;
          });
          if (this.appendToBody) {
            document.body.appendChild(this.$el);
          }
        } else {
          this.$el.removeEventListener('scroll', this.updatePopper);
          if (!this.closed) this.$emit('close');
        }
      }
    },

    computed: {
      style() {
        let style = {};
        if (!this.fullscreen) {
          style.marginTop = this.top;
          if (this.width) {
            style.width = this.width;
          }
        }
        return style;
      }
    },

    methods: {
      // 暂时没发现这个什么用
      getMigratingConfig() {
        return {
          props: {
            'size': 'size is removed.'
          }
        };
      },
      // 点击dialog自身
      handleWrapperClick() {
        if (!this.closeOnClickModal) return;
        this.handleClose();
      },
      // 关闭dialog
      handleClose() {
        // 如果有beforeClose,执行beforeClose
        if (typeof this.beforeClose === 'function') {
          this.beforeClose(this.hide);
        } else {
          // 否则隐藏
          this.hide();
        }
      },
      // 隐藏dialog
      hide(cancel) {
        if (cancel !== false) {
          this.$emit('update:visible', false);
          this.$emit('close');
          this.closed = true;
        }
      },
      updatePopper() {
        this.broadcast('ElSelectDropdown', 'updatePopper');
        this.broadcast('ElDropdownMenu', 'updatePopper');
      },
      // Dialog 打开动画结束时的回调
      afterEnter() {
        this.$emit('opened');
      },
      // Dialog 关闭动画结束时的回调
      afterLeave() {
        this.$emit('closed');
      }
    },

    mounted() {
      if (this.visible) {
        this.rendered = true;
        this.open();
        if (this.appendToBody) {
          document.body.appendChild(this.$el);
        }
      }
    },
    // 销毁前移除dom
    destroyed() {
      // if appendToBody is true, remove DOM node after destroy
      if (this.appendToBody && this.$el && this.$el.parentNode) {
        this.$el.parentNode.removeChild(this.$el);
      }
    }
  };
</script>

免责声明:文章转载自《element dialog源码》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C++枚举变量与switch关于标准化输出下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Electron学习笔记(十四)—— 常用api____dialog

https://www.electronjs.org/docs/api/dialog 对话框显示用于打开和保存文件、警报等的本机系统对话框。 在Electron的主线程上打开 const { dialog } = require('electron')console.log(dialog.showOpenDialog({ properties: ['ope...

让 el-dialog 居中,并且内容多的时候内部可以滚动

.el-dialog { position: absolute; top: 50%; left: 50%; margin: 0 !important; transform: translate(-50%, -50%); max-height: calc(100% - 30px); max- calc(...

Bootstrap:弹出框和提示框效果以及代码展示

一、Bootstrap弹出框 使用过JQuery UI的园友们应该知道,它里面有一个dialog的弹出框组件,功能也很丰富。与jQuery UI的dialog类似,Bootstrap里面也内置了弹出框组件。打开bootstrap 文档http://v3.bootcss.com/components/可以看到它的dialog是直接嵌入到bootstrap.j...

android 开发 对话框Dialog详解

转载请注明出处:红亮的专栏:http://blog.csdn.net/liang5630/article/details/44098899 Android中的对话框形式大致可分为五种:分别是一般对话框形式,列表对话框形式,单选按钮对话框,多选按钮对话框,自定义对话框。 在实际开发中,用系统的对话框会很少,因为太丑了,美工不愿意,多是使用自定义对话框。当然学...

弹出对话框之Dialog,你一定不知道这些

对于Dialog想必大家应该不陌生, 我们平长遇到的各种对话框就是Dialog了, 这个控件会在我们操作的任何界面弹出一个对话框, 且必须需要我们去操作它才可以关闭, 关于这个Dialog还是有许多地方值得我们去探讨的。 首先, 我们都知道最常用的对话框是这个AlertDialog, 不知道大家在使用这个控件的时候有没有注意到, 这个控件有两个包都包含它...

maximo功能修改笔记

      经过前几次的简单的修改系统功能,对maximo的bean开发已经有了一定了解,现在是耗时近两个礼拜来修改了一项系统功能,所用到的知识 Bean Fld, 下面我认真总结修改功能过程中的学到的知识: 目标效果一:          点击页面上新增的按钮,弹出一个dialog,然后在dialog里面可以进行多选,然后点击 “确定” 后,在当前的记录...