弹框组件的封装??

子组件=>

<template>
  <div class="dialog">
    <div>
      <p>{{title}}</p>
      <slot name="info"></slot>
      <slot name="img"></slot>
      <h5>
        <button @click="cancel">取消</button>
        <button @click="confirm">确定</button>
      </h5>
    </div>
  </div>
</template>
<script>
export default {
  name: "Dialog",
  data() {
    return {
      isShow: false
    };
  },
  props: {
    title: {
      type: String,
      default: "标题"
    }
  },
  methods: {
    cancel() {
      this.$emit("cancel");
    },
    confirm() {
      this.$emit("confirm");
    }
  }
};
</script>
<style lang="scss">
.dialog {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  position: absolute;
  z-index: 999;
  div {
    width: 70%;
    height: 35%;
    background-color: #fff;
    border-radius: 5px;
    position: absolute;
    padding: 20px 0;
    box-sizing: border-box;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: 45% auto;
    h5 {
      display: flex;
      justify-content: space-around;
    }
    p {
      margin: 30px 0;
      text-align: center;
    }
    button {
      width: 80px;
      height: 35px;
      border-radius: 5px;
      outline: none;
      background-color: transparent;
      border: 1px solid #ccc;
    }
  }
}
</style>

父组件 =>

<template>
  <div class="home">
    <!-- 弹框 -->
    <Dialog v-if="isShow" :title="title" @cancel="qx" @confirm="sure">
      <img slot="img" src="/img/none.png" alt />
      <p slot="info">产品基本信息</p>
    </Dialog>
    <button @click="show()">显示弹框</button>
  </div>
</template>

<script>
import Dialog from "@/components/dialog/dialog.vue";
export default {
  name: "Home",
  components: {
    GoTop,
    Dialog
  },
  data() {
    return {
      isShow: false,
      title: "您确定要删除吗?"
    };
  },
  methods: {
    show() {
      this.isShow = !this.isShow;
    },
    qx() {
      this.isShow = false;
    },
    sure() {
      this.isShow = false;
    }
  }
};
</script>

属性:title
可以传入的值:使用slot:img,商品信息
方法:cancel:取消按钮
confrim: 确定按钮,可以用了传值

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值