如果不是用vant组件库,推荐看:vue封装confirm弹框,通过transition设置动画

 

效果:

vue基于vant的popup组件封装confirm弹框

step:

1、components文件夹下新建MyConfirm文件夹,分别新建index.vue和index.js

  index.vue:

<template>
  <div class="my-confirm">
    <van-popup v-model="isShow">
      <div class="con_box">
        <h3>{{text.title}}</h3>
        <p>{{text.message}}</p>
        <div class="btn">
          <van-button @click="handleClose()" v-if="text.btn.cancelText">{{text.btn.cancelText}}</van-button>
          <van-button @click="handleOk()" :loading='submitLoading' v-if="text.btn.okText">{{text.btn.okText}}</van-button>
        </div>
      </div>
    </van-popup>
  </div>
</template>
<script>
export default {
  data() {
    return {
      submitLoading: false, // 每次创建弹框时loading状态都是false,所以在关闭时可以不用设置DOM.submitLoading = false
      isShow: true,
      text: {
        title: '提示',
        message: '确定删除此条信息?',
        btn: {
          okText: '确定',
          cancelText: '取消'
        }
      }
    }
  }
}
</script>
<style lang='less' scoped>
.my-confirm {
  /deep/ .van-popup {
    border-radius: 10px;
    .con_box {
      width: 270px;
      line-height: 1;
      text-align: center;
      color: #4d5c82;
      padding: 25px 15px 15px;
      box-sizing: border-box;
      > h3 {
        font-size: 20px;
      }
      > p {
        font-size: 17px;
        margin-top: 15px;
        margin-bottom: 20px;
        line-height: 26px;
      }
      .btn {
        display: flex;
        justify-content: space-between;
        > .van-button {
          display: block;
          width: 114px;
          background-color: #e0e5f5;
          text-align: center;
          line-height: 44px;
          font-size: 17px;
        }
        > .van-button:last-of-type {
          background-color: #1288fe;
          color: #ffffff;
        }
      }
    }
  }
}
</style>
View Code

相关文章: