vue.extend 自定义弹框

js

import Vue from 'vue'
import Toast from './Toast.vue'

const ToastBox = Vue.extend(Toast)

var instanceToast = ''

Toast.install = function (data) {
  if (!instanceToast) {
    instanceToast = new ToastBox({
      data
    }).$mount()
    document.body.appendChild(instanceToast.$el)
  }
  instanceToast.show = true
  instanceToast.title = data.title ? data.title : ''
  instanceToast.content = data.content ? data.content : ''
  instanceToast.type = data.type ? data.type : 'success'
}

export default Toast

vue

<template>
  <div v-show="show" class="myToast">
    <div class="mask" key="1" @click="show = false" @touchmove.prevent></div>
    <transition enter-active-class="animate__animated animate__fadeIn">
      <div v-show="show" class="pop" key="2">
        <div class="popTitle">
          <a-icon v-if="type == 'error'" class="toast-icon-error" type="close-circle" />
          <a-icon v-if="type == 'success'" class="toast-icon-success" type="check-circle" />
          <a-icon v-if="type == 'danger'" class="toast-icon-danger" type="exclamation-circle" />
          <p class="title-content">{{title}}</p>
          <a-icon @click="show = false" class="toast-close" type="close" />
        </div>
        <p class="toast-content">{{content}}</p>
      </div>
    </transition>
  </div>
</template>
<script>
export default {
  name: 'Toast',
  data() {
    return {
      show: false,
      title: '',
      content: '',
      type: 'success'
    }
  }
}
</script>
 <style lang="less" scoped>
.myToast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99999;
}

// 全局弹窗
.mask {
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  width: 100%;
  height: 100%;
}

.pop {
  min-height: 120px;
  width: 380px;
  background: #fff;
  border-radius: 5px;
  z-index: 9;
  text-align: center;
  animation-duration: 0.75s;
  .popTitle {
    line-height: 40px;
    padding: 0px 20px;
    text-align: left;
    display: flex;
    align-items: center;
    height: 50px;
    .title-content {
      flex: 1;
      font-size: 16px;
      font-weight: 700;
      color: rgba(0, 0, 0, 0.85);
      margin: 0;
      margin-left: 20px;
      margin-right: 20px;
    }
    .toast-icon-error {
      color: #f5222d;
      font-size: 20px;
    }
    .toast-icon-success {
      color: #52c41a;
      font-size: 20px;
    }
    .toast-icon-danger {
      color: #faad14;
      font-size: 20px;
    }
    .toast-close {
      color: rgba(0, 0, 0, 0.45);
      cursor: pointer;
    }
  }
  .toast-content {
    padding: 0px 20px 0px 60px;
    text-align: left;
  }
}
</style>

main.js

import Toast from './components/Toast/index'
Vue.prototype.$Toast = Toast.install

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值