解决了多次加载中
This commit is contained in:
parent
80d159f344
commit
509c3df652
@ -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)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user