Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
S
shop-new
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
王天霸
shop-new
Commits
72f9223f
提交
72f9223f
authored
7月 05, 2021
作者:
PC-20210205TDZC\Administrator
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加全局loading
上级
c325e758
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
2 行删除
+30
-2
AppMain.vue
src/layout/components/AppMain.vue
+1
-1
request.js
src/utils/request.js
+29
-1
没有找到文件。
src/layout/components/AppMain.vue
浏览文件 @
72f9223f
<
template
>
<section
class=
"app-main"
>
<section
class=
"app-main
loadingtext
"
>
<transition
name=
"fade-transform"
mode=
"out-in"
>
<keep-alive
:include=
"cachedViews"
>
<router-view
:key=
"key"
/>
...
...
src/utils/request.js
浏览文件 @
72f9223f
import
axios
from
'axios'
import
{
Notification
,
MessageBox
,
Message
}
from
'element-ui'
import
{
Notification
,
MessageBox
,
Message
,
Loading
}
from
'element-ui'
import
store
from
'@/store'
import
{
getToken
}
from
'@/utils/auth'
import
errorCode
from
'@/utils/errorCode'
let
loadingRequestCount
=
0
let
loadingInstance
const
showLoading
=
()
=>
{
if
(
loadingRequestCount
===
0
)
{
loadingInstance
=
Loading
.
service
({
target
:
'.loadingtext'
})
}
loadingRequestCount
++
}
const
hideLoading
=
()
=>
{
if
(
loadingRequestCount
<=
0
)
return
loadingRequestCount
--
if
(
loadingRequestCount
===
0
)
{
loadingInstance
.
close
()
}
}
axios
.
defaults
.
headers
[
'Content-Type'
]
=
'application/json;charset=utf-8'
// 创建axios实例
const
service
=
axios
.
create
({
...
...
@@ -14,6 +32,8 @@ const service = axios.create({
})
// request拦截器
service
.
interceptors
.
request
.
use
(
config
=>
{
showLoading
()
// 是否需要设置 token
const
isToken
=
(
config
.
headers
||
{}).
isToken
===
false
if
(
getToken
()
&&
!
isToken
)
{
...
...
@@ -28,6 +48,10 @@ service.interceptors.request.use(config => {
// 响应拦截器
service
.
interceptors
.
response
.
use
(
res
=>
{
setTimeout
(()
=>
{
hideLoading
()
},
200
)
// 未设置状态码则默认成功状态
const
code
=
res
.
data
.
code
||
200
;
// 返回所有数据的统一处理
...
...
@@ -90,6 +114,10 @@ service.interceptors.response.use(res => {
return
res
.
data
}
},
error
=>
{
setTimeout
(()
=>
{
hideLoading
()
},
200
)
// --- start ---- 开发时候用这段,把错误彻底抛出来 --- start ---
let
{
message
}
=
error
;
if
(
message
==
'Network Error'
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论