Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
任超
/
js.CadastralSystem
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
dcdd45a0
authored
2020-11-16 11:24:46 +0800
by
杨威
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
全局添加请求loading
1 parent
da73539c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
src/plugin/axios/index.js
src/plugin/axios/index.js
View file @
dcdd45a
...
...
@@ -2,6 +2,7 @@ import store from '../../store/index'
import
axios
from
'axios'
import
router
from
'../../router'
import
{
Message
,
MessageBox
}
from
'element-ui'
import
{
Loading
}
from
'element-ui'
;
import
{
httpStatus
}
from
'@/api/config'
// 创建一个 axios 实例
...
...
@@ -16,11 +17,17 @@ const service = axios.create({
})
function
errorLog
()
{
//请求完成关闭loading
// this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
loadingInstance
.
close
();
// });
MessageBox
.
alert
(
'报错了请联系管理员'
,
'消息提示'
,
{
confirmButtonText
:
'确定'
,
type
:
'warning'
})
}
//定义loading
let
loadingInstance
=
null
// 请求拦截器
service
.
interceptors
.
request
.
use
(
...
...
@@ -29,6 +36,13 @@ service.interceptors.request.use(
// const token = util.cookies.get('token')
// 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改
// config.headers['authkey'] = token
//请求发送成功显示loading
loadingInstance
=
Loading
.
service
({
lock
:
true
,
text
:
'Loading'
,
spinner
:
'el-icon-loading'
,
background
:
'rgba(0, 0, 0, 0.5)'
});
return
config
},
error
=>
{
...
...
@@ -43,6 +57,10 @@ service.interceptors.response.use(
// dataAxios 是 axios 返回数据中的 data
const
dataAxios
=
response
.
data
const
{
code
}
=
dataAxios
//请求完成关闭loading
// this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
loadingInstance
.
close
();
// });
// 根据 code 进行判断
if
(
code
===
undefined
)
{
// 如果没有 code 代表这不是项目后端开发的接口 比如可能是 D2Admin 请求最新版本
...
...
Please
register
or
sign in
to post a comment