Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
tswj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2022-05-28 01:39:29 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d9a78f1fa11891d6e5643f6c8bf525a0cb356964
d9a78f1f
1 parent
de4c7ff8
🎈 perf: axios请求头调整
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
src/utils/axios.js
src/utils/axios.js
View file @
d9a78f1
...
...
@@ -2,26 +2,33 @@ import axios from 'axios';
import
router
from
'@/router'
;
import
_
from
'lodash'
import
qs
from
'Qs'
import
{
parseQueryString
}
from
'@/utils/tools'
// import { parseQueryString } from '@/utils/tools'
axios
.
defaults
.
params
=
{
f
:
'voice'
,
};
/**
* @description 请求拦截器
*/
axios
.
interceptors
.
request
.
use
(
config
=>
{
const
url_params
=
parseQueryString
(
location
.
href
);
//
const url_params = parseQueryString(location.href);
// GET请求默认打上时间戳,避免从缓存中拿数据。
const
timestamp
=
config
.
method
===
'get'
?
(
new
Date
()).
valueOf
()
:
''
;
// 发送请求前
if
(
config
.
method
===
'post'
&&
(
config
.
url
.
indexOf
(
'a=upload'
)
===
-
1
&&
config
.
url
.
indexOf
(
'upload.qiniup.com'
)
===
-
1
))
// 上传相关接口需要屏蔽掉
// 上传相关接口需要屏蔽掉封装, 不能序列化数据会报错。
if
(
config
.
method
===
'post'
&&
(
config
.
url
.
indexOf
(
'a=upload'
)
===
-
1
&&
config
.
url
.
indexOf
(
'upload.qiniup.com'
)
===
-
1
)
)
{
// POST PHP需要修改数据格式
config
.
data
=
qs
.
stringify
(
config
.
data
)
}
// 绑定默认请求头
config
.
params
=
_
.
merge
(
config
.
params
,
{
f
:
'voice'
,
timestamp
,
})
return
config
;
...
...
@@ -36,9 +43,9 @@ axios.interceptors.request.use(
*/
axios
.
interceptors
.
response
.
use
(
response
=>
{
// 默认显示
// 默认显示
错误提示
response
.
data
.
show
=
true
;
// C/B授权拼接头特殊标识,openid_x
// C/B
授权拼接头特殊标识,openid_x
let
userType
=
router
&&
router
.
currentRoute
.
value
.
href
?.
indexOf
(
'business'
)
>
0
?
'b'
:
'c'
;
if
(
response
.
data
.
code
===
401
)
{
// 特殊标识-带此标识报错不显示
...
...
Please
register
or
login
to post a comment