vue 简易弹框

很简易的弹出框,不想写样式了,凑活看吧在这里插入图片描述

modal.vue

<!--
 * @Description: 
 * @Version: 1.0
 * @author: shihaixia
 * @Date: 2021-09-14 15:38:27
-->
<template>
  <transition name="mask-bg-fade">
    <div class="modal" v-if="visible">
      <div
        class="modal-content"
        :style="{
          backgroundImage: 'url(' + backgroundImage + ')',
        }"
      >
        <header class="modal-head">
          <slot name="header">{{ title }}</slot>
        </header>
        <main>
          <slot></slot>
        </main>
        <footer class="modal-foot">
          <slot name="footer">
            <button @click="btnSave">确定</button>
            <button @click="btnClick">关闭</button>
          </slot>
        </footer>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  data () {
    return {

    }
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: "操作"
    },
    backgroundImage: {
      type: String,
      default: ""
    },
  },
  methods: {
    btnClick () {
      this.$emit("close")
    },
    btnSave () {
      this.$emit("confirm")
    }
  }
}

</script>

<style>
.modal {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
  align-items: center;
  display: flex;
}
.modal-content {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: block;
  min-width: 300px;
  min-height: 300px;
  background: #fff;
  box-shadow: 0px 0px 10px 0px rgba(192, 196, 204, 1);
  border-radius: 6px;
  background-repeat: no-repeat;
  background-size: cover;
  margin: 0 auto;
}
.modal-head {
  font-size: 24px;
  /* border-bottom: 1px solid black; */
  margin: 20px 0;
  color: white;
}
.modal-foot {
  position: absolute;
  bottom: 10px;
}
</style>

组件内使用

<!--
 * @Description: 
 * @Version: 1.0
 * @author: shihaixia
 * @Date: 2021-09-14 14:57:57
-->
<template>
  <div class="hello">
    <button @click="visible = true" class="btn">插槽</button>
    <Modal
      :title="title"
      :visible.sync="visible"
      @confirm="confirm"
      @close="handleclose"
      :backgroundImage="backgroundImage"
    >
      <div class="content">内容</div>
      <!-- <template>
        <div class="hignlight">欢迎来到XXX</div>
        <div class="content">是否封包</div>
      </template> -->
      <!-- 可自定义 footer -->
      <!-- <template slot="footer">
        <button class="btn" @click="visible = false">我知道了</button>
      </template> -->
    </Modal>
  </div>
</template>

<script>
import Modal from "./Notice/Modal.vue";
export default {
  name: "HelloWorld",
  components: {
    Modal,
  },
  props: {
  },
  data () {
    return {
      visible: false,
      title: "标题",
      backgroundImage: "https://st-gdx.dancf.com/gaodingx/0/uxms/design/20200425-114623-8814.png?x-oss-process=image/resize,w_932/interlace,1,image/format,webp"
    };
  },
  created () {

  },
  methods: {
    confirm () {

    },
    handleclose () {
      this.visible = false
    },
  }
};
</script>
<style scoped>
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值