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-06-30 01:18:29 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d9032dd586599a2de6ad03fef501f90f828dacc8
d9032dd5
1 parent
9ce556b6
✨ feat(axios模块): post请求判断是否使用qs状态使用封装函数
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
src/utils/axios.js
src/utils/tools.js
src/utils/axios.js
View file @
d9032dd
...
...
@@ -2,13 +2,14 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-28 10:17:40
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-30 0
0:10:5
0
* @LastEditTime: 2022-06-30 0
1:16:4
0
* @FilePath: /tswj/src/utils/axios.js
* @Description:
*/
import
axios
from
'axios'
;
import
router
from
'@/router'
;
import
qs
from
'Qs'
import
{
strExist
}
from
'@/utils/tools'
// import { parseQueryString } from '@/utils/tools'
axios
.
defaults
.
params
=
{
...
...
@@ -23,15 +24,13 @@ axios.interceptors.request.use(
// 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'
)
{
// 上传相关接口需要屏蔽掉封装, 不能序列化,数据会报错。
if
(
!
strExist
([
'a=upload'
,
'upload.qiniup.com'
],
config
.
url
))
{
// POST PHP需要修改数据格式
config
.
data
=
qs
.
stringify
(
config
.
data
)
}
}
// 绑定默认请求头
config
.
params
=
{
...
config
.
params
,
timestamp
}
return
config
;
...
...
src/utils/tools.js
View file @
d9032dd
/*
* @Date: 2022-04-18 15:59:42
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-
29 22:35:51
* @LastEditTime: 2022-06-
30 01:15:33
* @FilePath: /tswj/src/utils/tools.js
* @Description: 文件描述
*/
...
...
@@ -58,4 +58,17 @@ const parseQueryString = url => {
return
json
;
}
export
{
formatDate
,
wxInfo
,
hasEllipsis
,
parseQueryString
};
/**
* 字符串包含字符数组中字符的状态
* @param {*} array 字符数组
* @param {*} str 字符串
* @returns 包含状态
*/
const
strExist
=
(
array
,
str
)
=>
{
const
exist
=
array
.
filter
(
arr
=>
{
if
(
str
.
indexOf
(
arr
)
>=
0
)
return
str
;
})
return
exist
.
length
>
0
}
export
{
formatDate
,
wxInfo
,
hasEllipsis
,
parseQueryString
,
strExist
};
...
...
Please
register
or
login
to post a comment