From 509c3df65215dd2973ca91a62b4ac75a88db7ccd Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Mon, 26 Oct 2020 15:10:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/base.ts | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/api/base.ts b/src/api/base.ts index a4fa823..aa3c4fd 100644 --- a/src/api/base.ts +++ b/src/api/base.ts @@ -11,24 +11,43 @@ import store from '@/store'; export interface Get { (url: string, params?: unknown, config?: AxiosRequestConfig): Promise>; } -const login: MessageType[] = [] +let login: MessageType; +let count = 0; axios.interceptors.request.use((config)=>{ - login.push(message.loading('加载中..', 0)) + if(count == 0){ + login = message.loading('加载中..', 0) + } + count++; return config; }) axios.interceptors.response.use((response)=>{ // console.log(response) - login[0](); - login.splice(0,1); + if(count != 0){ + setTimeout(()=>{ + count--; + if(count == 0){ + login(); + } + console.log(count) + }, 1000) + } + if(response.data.code == 1001){ store.commit("login", false) router.push("/") } return response; },(error)=>{ - login[0](); - login.splice(0,1); + if(count != 0){ + setTimeout(()=>{ + count--; + if(count == 0){ + login(); + } + console.log(count) + }, 1000) + } message.error(error.response.data.message) return Promise.reject(error) })