解决了多次加载中

This commit is contained in:
luyuan 2020-10-26 15:10:21 +08:00
parent 80d159f344
commit 509c3df652
Signed by: theluyuan
GPG Key ID: A7972FD973317FF3

View File

@ -11,24 +11,43 @@ import store from '@/store';
export interface Get { export interface Get {
<T>(url: string, params?: unknown, config?: AxiosRequestConfig): Promise<CustomSuccessData<T>>; <T>(url: string, params?: unknown, config?: AxiosRequestConfig): Promise<CustomSuccessData<T>>;
} }
const login: MessageType[] = [] let login: MessageType;
let count = 0;
axios.interceptors.request.use((config)=>{ axios.interceptors.request.use((config)=>{
login.push(message.loading('加载中..', 0)) if(count == 0){
login = message.loading('加载中..', 0)
}
count++;
return config; return config;
}) })
axios.interceptors.response.use((response)=>{ axios.interceptors.response.use((response)=>{
// console.log(response) // console.log(response)
login[0](); if(count != 0){
login.splice(0,1); setTimeout(()=>{
count--;
if(count == 0){
login();
}
console.log(count)
}, 1000)
}
if(response.data.code == 1001){ if(response.data.code == 1001){
store.commit("login", false) store.commit("login", false)
router.push("/") router.push("/")
} }
return response; return response;
},(error)=>{ },(error)=>{
login[0](); if(count != 0){
login.splice(0,1); setTimeout(()=>{
count--;
if(count == 0){
login();
}
console.log(count)
}, 1000)
}
message.error(error.response.data.message) message.error(error.response.data.message)
return Promise.reject(error) return Promise.reject(error)
}) })