定义一个 count 用来记 请求了几个接口
在 (请求拦截器) 中让 count++ 加几个就说明请求了几个接口
在 (响应拦截器) 中让 count- - 当减到0 之后就是说,接口全部请求完成了,清除loading
import {Loading} from 'element-ui'
let loadingInstance = null;
var count = 0;
// 添加请求拦截器
Service.interceptors.request.use((config) => {
count ++
loadingInstance = Loading.service({
lock: true,
text: 'loading...'
})
return config
})
// 添加响应拦截器
Service.interceptors.response.use((response) => {
count--
if(count == 0){
loadingInstance.close()
}
return response.data
}