如何做一个H5弹窗组件复用?

关闭按钮在内部时

<template>
  <div class="tipPop">
      <div class="tipPop-show">
        <div>
           <img class="close" src="@/assets/img/close.png" @click.stop="handleClsoeData"/>
          <slot></slot>
        </div>
      </div>
       
  </div>
</template>

<script>
export default {
  props:{
    serviceClose:Boolean
  },
  methods:{
    handleClsoeData() {
     
      this.$parent.handleMessageClose();
    },
  }

}
</script>
<style lang="less" scoped>
.tipPop{
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: rgba(0,0,0,.5);
    z-index: 888;
    .tipPop-show{
      position: fixed;
      width: 280px;
      min-height: 160px;
      padding: 18px;
      background: #fff;
      left: 50%;
      top: 50%;
      transform: translate(-50%,-50%);
      border-radius: 9px; 
      z-index: 999;
    }
   
    .close{
        position: absolute;
        right: 3%;
        top: 4%;
        width: 20px;
        height: 20px;
        z-index: 9999;
      }
      
  }
</style>

当关闭按钮在外部时,需要根据内容大小决定

<template>
  <div class="custPop-bg" @click="handleClsoeData">
    <div class="bg-item">
      <div class="tipPop-show">
        <slot></slot>
      </div>
      <div class="close"  >
        <van-icon name="cross" class="close-icon" @click="handleClsoeData"/>
      </div>

    </div>

</div>
</template>

<script>
export default {
  props:{
    serviceClose:Boolean
  },
  methods:{
    handleClsoeData() {
   
      this.$parent.handleMessageClose();
    },
  }

}
</script>
<style lang="less" scoped>
.custPop-bg{
    position: fixed;
    width: 100%;
    height: 100vh;
    left: 0;
    top: 0;
    background: rgba(255,255,255,0);
    display: flex;
    align-items: center;
    justify-items: center;
    z-index: 888;
    .bg-item{
      // width: 70%;
      margin: 0 auto;
    }

}

    .tipPop-show{
      width: 70%;
      height: auto;
      margin: 0 auto;
      padding: 10px;
      color: #fff;
      background: rgba(0,0,0,0.7);
      border-radius: 9px; 
    }

    .close{
      width: 100%;
      text-align: center;
      margin-top: 24rpx;
      .close-icon{
        width: 20px;
        height: 20px;
        padding: 5px;
        color: #fff;
        font-size: 16px;
        line-height: 20px;
        margin-top: 10px;
        background: rgba(0,0,0,0.7);
        border-radius: 50%;
      }
    }
</style>

俩个组件根据需要在外部引入

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值