VueのUIコンポーネントライブラリのloadingはどうしますか?車輪が大きいほうがよい
48215 ワード
先に原文のリンクを行います:リンクの説明1、1つのフォルダ、1つのloadingを追加します.js一つloading.vue、ブロックを要求するファイル(1)loading.js
(2)vueフォルダ
3、ファイルのブロックを要求する
import Loading from './loading.vue';
import Vue from 'vue';
export default()=>{
let LoadingComponent=Vue.extend(Loading);
let child=new LoadingComponent({//
el:document.createElement("div"),
data:{
flag:false,
},
methods:{
handlemount(){
this.flag=true;
},
handleDestory(){
this.flag=false;
}
}
})
document.body.appendChild(child.$mount().$el)
return child;
}
(2)vueフォルダ
<template>
<div class="loader" v-if="flag">
<!-- // v-if 。 -->
<div class="loader-inner">
<div class="loader-line-wrap">
<div class="loader-line"></div>
</div>
<div class="loader-line-wrap">
<div class="loader-line"></div>
</div>
<div class="loader-line-wrap">
<div class="loader-line"></div>
</div>
<div class="loader-line-wrap">
<div class="loader-line"></div>
</div>
<div class="loader-line-wrap">
<div class="loader-line"></div>
</div>
</div>
</div>
</template>
<script>
export default {
name:"Movie"
}
</script>
<style scoped lang="less">
.loader {
background: #000;
background: radial-gradient(#222, #000);
bottom: 0;
left: 0;
overflow: hidden;
position: fixed;
right: 0;
top: 0;
z-index: 99999;
}
.loader-inner {
bottom: 0;
height: 60px;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
width: 100px;
}
.loader-line-wrap {
animation:
spin 2000ms cubic-bezier(.175, .885, .32, 1.275) infinite
;
box-sizing: border-box;
height: 50px;
left: 0;
overflow: hidden;
position: absolute;
top: 0;
transform-origin: 50% 100%;
width: 100px;
}
.loader-line {
border: 4px solid transparent;
border-radius: 100%;
box-sizing: border-box;
height: 100px;
left: 0;
margin: 0 auto;
position: absolute;
right: 0;
top: 0;
width: 100px;
}
.loader-line-wrap:nth-child(1) { animation-delay: -50ms; }
.loader-line-wrap:nth-child(2) { animation-delay: -100ms; }
.loader-line-wrap:nth-child(3) { animation-delay: -150ms; }
.loader-line-wrap:nth-child(4) { animation-delay: -200ms; }
.loader-line-wrap:nth-child(5) { animation-delay: -250ms; }
.loader-line-wrap:nth-child(1) .loader-line {
border-color: hsl(0, 80%, 60%);
height: 90px;
width: 90px;
top: 7px;
}
.loader-line-wrap:nth-child(2) .loader-line {
border-color: hsl(60, 80%, 60%);
height: 76px;
width: 76px;
top: 14px;
}
.loader-line-wrap:nth-child(3) .loader-line {
border-color: hsl(120, 80%, 60%);
height: 62px;
width: 62px;
top: 21px;
}
.loader-line-wrap:nth-child(4) .loader-line {
border-color: hsl(180, 80%, 60%);
height: 48px;
width: 48px;
top: 28px;
}
.loader-line-wrap:nth-child(5) .loader-line {
border-color: hsl(240, 80%, 60%);
height: 34px;
width: 34px;
top: 35px;
}
@keyframes spin {
0%, 15% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
</style>
3、ファイルのブロックを要求する
import Vue from 'vue'
import axios from 'axios'
import store from '@/store'
import { VueAxios } from './axios'
import {Modal, notification,message} from 'ant-design-vue'
import { ACCESS_TOKEN } from "@/store/mutation-types"
// loading
import loading from 'url..........................'
let vm=loading()
let apiBaseUrl = window._CONFIG['domianURL'] || "/jeecg-boot";
console.log("apiBaseUrl= ",apiBaseUrl)
// axios
const service = axios.create({
baseURL: apiBaseUrl, // api base_url
timeout: 9000 //
})
const err = (error) => {
if(error.message.includes('timeout')){
message.error(' !')
}
if (error.response) {
let data = error.response.data
const token = Vue.ls.get(ACCESS_TOKEN)
console.log("------ ------",token)
console.log("------ ------",error.response.status)
switch (error.response.status) {
case 403:
notification.error({ message: ' ', description: ' ',duration: 4})
break
case 500:
//notification.error({ message: ' ', description:'Token , !',duration: 4})
if(token && data.message=="Token , "){
// update-begin- --- author:scott ------ date:20190225 ---- for:Token , ----
// store.dispatch('Logout').then(() => {
// window.location.reload()
// })
Modal.error({
title: ' ',
content: ' , , ',
okText: ' ',
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
})
// update-end- --- author:scott ------ date:20190225 ---- for:Token , ----
}
break
case 404:
notification.error({ message: ' ', description:' , !',duration: 4})
break
case 504:
notification.error({ message: ' ', description: ' '})
break
case 401:
notification.error({ message: ' ', description:' , ',duration: 4})
if (token) {
store.dispatch('Logout').then(() => {
setTimeout(() => {
window.location.reload()
}, 1500)
})
}
break
default:
notification.error({
message: ' ',
description: data.message,
duration: 4
})
break
}
}
return Promise.reject(error)
};
// request interceptor
service.interceptors.request.use(config => {
const token = Vue.ls.get(ACCESS_TOKEN)
if (token) {
config.headers[ 'X-Access-Token' ] = token // token
}
if(config.method=='get'){
if(config.url.indexOf("sys/dict/getDictItems")<0){
config.params = {
_t: Date.parse(new Date())/1000,
...config.params
}
}
}
// loadin
vm.handlemount();
return config
},(error) => {
return Promise.reject(error)
})
// response interceptor
service.interceptors.response.use(
(response) => {
// loading
vm.handleDestory();
return response.data
},err)
const installer = {
vm: {},
install (Vue, router = {}) {
Vue.use(VueAxios, router, service)
}
}
export {
installer as VueAxios,
service as axios
}