美文网首页
vue封装js调用弹窗

vue封装js调用弹窗

作者: lesdom | 来源:发表于2020-11-19 12:44 被阅读0次

组件

components/orderDialog
order.vue

<template>
  <div class="message" v-if="visible">
    <div class="content">              
      <i class="el-icon-close close-icon" @click="visible=false"></i>   
      <p class="order-title">预约试听</p>      
    </div>    
  </div>
</template>

<script>
  export default {
    name: "Toast",
    data() {
      return {              
        time: 3000, // 消失时间,默认3秒后消失
        visible: false,                          
      }
    },
    mounted() {
      // this.close()
    },
    methods: {
      close() {
        window.setTimeout(() =>{
          this.visible = false
        }, this.time);
      },            
    }
  }
</script>
<style scoped>
.message {    
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;  
  z-index: 999;  
  background-color: rgba(0,0,0,0.3);
  display: flex;

}
.content {
  width: 618px;
  height: 582px;
  background-color: #fff;
  border-radius: 18px;
  margin: 15vh auto 0;
  position: relative;
  text-align: center;
}
.close-icon {
  font-size:29px;
  color:#999999;
  position: absolute;
  top: 30px;
  right: 30px;
  cursor: pointer;
}
.order-title {  
  font-size: 36px;
  font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  font-weight: bold;
  color: #585858; 
  margin: 100px auto 50px; 
  text-align: center;
}
</style>

order.js

import Vue from 'vue'
import Order from './order.vue'

const OrderBox = Vue.extend(Order)
Order.install = function (data) {  
  let instance = new OrderBox({
    data
  }).$mount()

  document.body.appendChild(instance.$el)

  Vue.nextTick(() => {
    instance.visible = true
  })
}

export default Order

引用

main.js

import Order from '@/components/orderDialog/order'
Vue.prototype.$Order = Order.install;

使用

this.$Order({})

相关文章

网友评论

      本文标题:vue封装js调用弹窗

      本文链接:https://www.haomeiwen.com/subject/wawkiktx.html