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 {
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) => {
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'
const vm = new Vue()
axios.interceptors.request.use(function (config) {
vm.$showLoading()
vm.$showchangeProgress()
return config
}, function (error) {
vm.$hideLoading()
vm.$hidechangeProgress()
return Promise.reject(error)
})
axios.interceptors.response.use(function (response) {
vm.$hideLoading()
vm.$hidechangeProgress()
return response
}, function (error) {
vm.$hideLoading()
vm.$hidechangeProgress()
return Promise.reject(error)
})