vue封装DiaLong组件封装

<template>
  <transition name="dialog-fade">
    <!-- 遮罩 -->
    <div class="d-dialog_wrapper" v-show="visiable" @click.self="closeDialog">
      <div
        :class="['d-dialog', mimicry ? 'is-mimicry' : '']"
        :style="{ width: width, 'margin-top': top }"
      >
        <div class="d-dialog_header">
          <!-- title支持slot插槽 -->
          <slot name="title">
            <span class="d-dialog_title">{{ title }}</span>
          </slot>
          <el-button
            circle
            class="d-dialog_headerbtn el-icon-circle-close"
            @click="closeDialog"
          ></el-button>
        </div>
        <div class="d-dialog_body">
          <!-- 默认插槽 -->
          <slot></slot>
        </div>
        <div class="d-dialog_footer" v-if="$slots.footer">
          <slot name="footer"></slot>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "DDialog",
  data() {
    return {}
  },
  methods: {
    closeDialog() {
      this.$emit("update:visiable", false)
    },
  },
  components: {},
  props: {
    title: {
      type: String,
      default: "提示",
    },
    width: {
      type: String,
      default: "90%",
    },
    top: {
      type: String,
      default: "15vh",
    },
    visiable: {
      type: Boolean,
      default: false,
    },
    mimicry: {
      type: Boolean,
      default: false,
    },
  },
  created() {},
  mounted() {},
  computed: {},

  watched: {},
}
</script>
<style scoped lang="less">
// 重点学习遮罩的实现
.d-dialog_wrapper {
  position: fixed;
  top: 0;
  right: 0;
  bottom: -3vh;
  left: 0;
  overflow: auto;
  margin: 0;
  z-index: 2001;
  background-color: rgba(0, 0, 0, 0.5);
  .d-dialog {
    position: relative;
    margin: 15vh auto 50px;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    box-sizing: border-box;

    &_header {
      padding: 20px 20px 10px;
      display: flex;
      justify-content: space-between;
      .d-dialog_title {
        line-height: 24px;
        font-size: 18px;
        color: #303133;
      }
      .d-dialog_headerbtn {
        padding: 0;
        background: transparent;
        border: none;
        outline: none;
        cursor: pointer;
        font-size: 16px;
        .d-icon-close {
          color: 909399;
        }
      }
    }
    &_body {
      padding: 30px 20px;
      color: #606266;
      font-size: 14px;
      // CSS 属性 word-break 指定了怎样在单词内断行
      word-break: break-all;
      max-height: 300px;
      overflow-y: scroll;
    }
    &_footer {
      padding: 10px 20px 20px;
      text-align: right;
      box-sizing: border-box;
      /deep/ .d-button:first-child {
        margin-right: 20px;
      }
    }
  }
  // 拟态风格
  .d-dialog.is-mimicry {
    border-radius: 12px;
    box-shadow: inset 7px 14px 23px #dadada, inset -7px -14px 23px #eeeeee;
  }
}
.dialog-fade-enter-active {
  animation: fade 0.5s;
}

.dialog-fade-leave-active {
  animation: fade 0.39s reverse;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(-3vh);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值