Vue main.js引入全局progress组件原型实例,加载中动画组件原型实例

main.js引入全局progress组件原型实例


main.js引入全局组件原型实例

progress 实例

1. progress.vue

<template>
  <div v-show="isShowProgress" class="el-loading-mask is-fullscreen">
    <div class="el-loading-spinner">
      <el-progress :percentage="percentage" stroke-width="12"></el-progress>
    </div>
  </div>
</template>

<script>
export default {
  name: "loading",
  data() {
    return {
      // 进度条
      isShowProgress: false,
      percentage: 70,
    }
  },
}
</script>

<style lang="scss" scoped>
// 进度条
.el-loading-mask {
  // background: transparent;
  z-index: 10001;
  .el-progress {
    position: fixed;
    left: 20px;
    right: 20px;
    bottom: 20px;
  }
}
</style> 

2. proto.js

import progressVue from './progress.vue'
export default {
  install: (Vue) => {
    // ------------------ progress 进度条 ------------------
    const ProgressComponent = Vue.extend(progressVue);
    const newProgressCom = new ProgressComponent();
    const tpProgress = newProgressCom.$mount().$el;
    document.body.appendChild(tpProgress);
    Vue.prototype.$showchangeProgress = () => {
      newProgressCom.isShowProgress = true
    }
    Vue.prototype.$hidechangeProgress = () => {
      newProgressCom.isShowProgress = false
    }
  }
}

引入及使用

main.js

// 全局组件原型实例
import publicProto from '@/common/js/proto.js'
Vue.use(publicProto)

http.js

import Vue from 'vue'
// 定义Vue实例 调用全局显示和关闭loading方法
const vm = new Vue()
// 请求拦截
axios.interceptors.request.use(function (config) {
  // 在这里调用 显示loading方法
  vm.$showLoading()
  vm.$showchangeProgress()
  return config
}, function (error) {
  vm.$hideLoading()
  vm.$hidechangeProgress()
  // 在请求出错调用 关闭loading方法
  return Promise.reject(error)
})
// 响应拦截
axios.interceptors.response.use(function (response) {
  // 在这里调用 关闭loading方法
  vm.$hideLoading()
  vm.$hidechangeProgress()
  return response
}, function (error) {
  // 在这里调用 关闭loading方法
  vm.$hideLoading()
  vm.$hidechangeProgress()
  return Promise.reject(error)
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值