import { Loading } from "element-ui";
let loading
function startLoading() {
loading = Loading.service({
lock: true,
text: '加载中……',
background: 'rgba(0, 0, 0, 0.7)'
})
}
function endLoading() {
loading.close()
}
let needLoadingRequestCount = 0
export function showFullScreenLoading() {
if (needLoadingRequestCount === 0) {
startLoading()
}
needLoadingRequestCount++
}
export function tryHideFullScreenLoading() {
if (needLoadingRequestCount <= 0) return
needLoadingRequestCount--
if (needLoadingRequestCount === 0) {
endLoading()
}
}
//请求拦截器
showFullScreenLoading()
return config //此处上调用
}, error => {
return Promise.reject(error)
})
//响应拦截器
tryHideFullScreenLoading()
return { data, code, msg } //此处上调用
}, error => {
if (error.text == '') {
return Promise.resolve({ data: {}, code: 0 })
}
vue 请求拦截器响应拦截器添加Loading... 工具函数
最新推荐文章于 2024-05-24 18:11:10 发布