el-dialog的再封装(头部,尾部)

本文介绍了一个可定制的E-dialog组件,支持动态内容展示、显示/隐藏控制、自定义footer以及开放/关闭/确认操作的钩子。通过实例代码演示了如何在Vue中使用该组件进行银行账号表单的弹窗操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.实现效果如下:(完整代码见底部)

 db38347094b84494ab3d69379f9626b5.png

 二.入参和反参

入参:

title:标题
show:控制显示和隐藏
customFooter:是否自定义底部操作栏
width:宽度

----可根据实际需求继续扩展----
反参:

this.$emit("openDlg");  提供打开窗口的钩子openDlg
this.$emit("staticCloseDlg");    提供关闭窗口的钩子staticCloseDlg
this.$emit("confirm");    提供点击确定的钩子confirm

 三.引用

<e-dialog
      @confirm="backAccConfirm"
      @staticCloseDlg="staticCloseDlg"
      :title="diaTitle"
      :show.sync="dialogVisible"
    >
      <bank-acc-form
        @closeDlg="closeDlg"
        ref="backAccForm"
        slot="content"
        :oriForm="oriForm"
      ></bank-acc-form>
    </e-dialog>

四.完整代码

<template>
  <div class="e-dialog">
    <el-dialog
      :title="title"
      @close="staticCloseDlg"
      :width="width"
      :visible.sync="display"
      :close-on-click-modal="false"
    >
      <transition name="slide-fade" mode="out-in">
        <slot name="content" v-if="display"></slot>
      </transition>
      <!-- footer -->
      <div slot="footer" v-if="!customFooter">
        <el-button size="small" type="primary" icon="el-icon-check" @click="confirm">确定</el-button>
        <el-button size="small" class="cancel-btn" icon="el-icon-close" @click="cancel"
          >取消</el-button
        >
      </div>
      <div v-else slot="footer">
        <slot name="footer"></slot>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "e-dialog",
  props: {
    title: {
      //标题
      type: String,
      default: "title",
    },
    show: {
      //显隐
      type: Boolean,
      default: false,
    },
    customFooter: {
      //是否自定义footer
      type: Boolean,
      default: false,
    },
    width: {
      //是否自定义footer
      type: String,
      default: "50%",
    },
  },
  watch: {
    show: function (newValue) {
      this.display = newValue; // show改变是同步子组件display的值
      if (newValue) {
        this.$emit("openDlg"); //打开弹窗的时候,抛出一个钩子用于外部组件预处理
      }
    },
    display: function (newValue) {
      this.$emit("update:show", newValue); // display改变时同步父组件show的值
    },
  },
  data() {
    return {
      display: false,
    };
  },
  methods: {
    cancel() {
      this.display = false;
    },
    staticCloseDlg() {
      this.$emit("staticCloseDlg");
    },
    confirm() {
      //点击确定的关闭事件是通过父节点进行处理
      this.$emit("confirm");
    },
  },
};
</script>

<style scoped lang="scss">
.e-dialog {
  .slide-fade-enter-active {
    transition: all 0.3s ease;
  }
  .slide-fade-leave-active {
    transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
  }
  .slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
    // transform: translateX(100px);
    opacity: 0;
  }
  /deep/.el-dialog {
    border-radius: 8px;
  }

  /deep/.el-dialog__body {
    padding: 10px 40px !important;
  }

  /deep/.el-dialog__header {
    background: #1d78d5;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
  }

  /deep/.el-dialog__title {
    color: white;
  }

  /deep/.el-dialog__headerbtn .el-dialog__close {
    color: white !important;
  }
}
</style>


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一路追求匠人精神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值