Vue封装弹出层

views创建文件

代码如下

<template>
  <div class="zk-box">
    <div class="zk-flex zk-pd">
      <div class="zk-btn" @click="alerts">测试提示框</div>
      <Eject type="alert" @took="okfall" :showstate="showa">
        <span slot="tlt">提示</span>
        <div slot="text">这是一个提示弹窗</div>
      </Eject>
    </div>
    <div class="zk-flex zk-pd">
      <div class="zk-btn zk-blue" @click="confirms">测试对话框</div>
      <Eject type="confirm" @took="okfall2" @tocancel="cancelfall" :showstate="showc">
        <span slot="tlt">确认</span>
        <div slot="text">{{msg}}</div>
      </Eject>
    </div>
  </div>
</template>
<script>
import Eject from "../components/Tan";
export default {
  name: "demo",
  components: {
    Eject,
  },
  data() {
    return {
      showa: false,
      showc: false,
      msg: "",
    };
  },
  methods: {
    alerts() {
      this.showa = true;
    },
    confirms() {
      this.showc = true;
      this.msg = "这是一个对话的弹窗";
    },
    okfall() {
      this.showa = false;
    },
    cancelfall() {
      this.showc = false;
    },
    okfall2() {
      this.showc = false;
    },
  },
};
</script>
<style>
.zk-box {
  display: flex;
  line-height: 0.65rem;
  font-size: 0.26rem;
  color: #333;
  padding: 4.5rem 0;
}
.zk-flex {
  flex: 1;
}
.zk-pd {
  padding: 0.5rem 0.1rem;
}
.zk-btn {
  display: block;
  line-height: 3rem;
  text-align: Center;
  color: #fff;
  border-radius: 0.12rem;
  background: #488bf1;
}
.zk-blue {
  background: #488bf1;
}
</style>

组件

<template>
  <div class="kz-cont" v-show="showstate">
    <div class="kz-wrapper">
      <div class="kz-text">
        <strong>
          <slot name="text"></slot>
        </strong>
      </div>
      <div class="footer">
        <div @click="tocancel" class="kz-btn">取消</div>
        <div class="kz-btn" @click="took">确定</div>
      </div>
    </div>
    
  </div>
</template>
<script>
export default {
  name: "eject",
  props: ["type", "showstate"],
  methods: {
    tocancel: function () {
      this.$emit("tocancel");
    },
    took: function () {
      this.$emit("took");
    },
  },
};
</script>
<style scoped>
.kz-cont {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.3);
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
}
.kz-cont:after {
  content: "";
  display: inline-block;
  width: 0;
  height: 100%;
  visibility: hidden;
  vertical-align: middle;
}
.kz-wrapper {
  display: inline-block;
  vertical-align: middle;
  background: #fff;
  color: #333333;
  border-radius: 5px;
  max-width: 100%;
}
.kz-text {
  text-align: center;
  padding: 20px 75px;
}
.footer {
  display: flex;
  border-top: 1px solid #e5e5e5;
  color: #488bf1;
}
.kz-btn {
  flex: 1;
  padding: 15px;
}
.kz-btn + .kz-btn {
  border-left: 1px solid #e5e5e5;
}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

张清悠

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

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

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

打赏作者

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

抵扣说明:

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

余额充值