Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
49f39de7
Commit
49f39de7
authored
Jul 03, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(axios): use `defHttp` like `axios`
当非GET请求并且同时存在data和params,不再忽略data。使defHttp的用法习惯接近axios原生配置 fixed: #850
parent
8819af08
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
3 deletions
+15
-3
index.ts
src/utils/http/axios/index.ts
+15
-3
No files found.
src/utils/http/axios/index.ts
View file @
49f39de7
...
@@ -61,6 +61,7 @@ const transform: AxiosTransform = {
...
@@ -61,6 +61,7 @@ const transform: AxiosTransform = {
switch
(
code
)
{
switch
(
code
)
{
case
ResultEnum
.
TIMEOUT
:
case
ResultEnum
.
TIMEOUT
:
timeoutMsg
=
t
(
'
sys.api.timeoutMessage
'
);
timeoutMsg
=
t
(
'
sys.api.timeoutMessage
'
);
break
;
default
:
default
:
if
(
message
)
{
if
(
message
)
{
timeoutMsg
=
message
;
timeoutMsg
=
message
;
...
@@ -90,6 +91,8 @@ const transform: AxiosTransform = {
...
@@ -90,6 +91,8 @@ const transform: AxiosTransform = {
config
.
url
=
`
${
apiUrl
}${
config
.
url
}
`
;
config
.
url
=
`
${
apiUrl
}${
config
.
url
}
`
;
}
}
const
params
=
config
.
params
||
{};
const
params
=
config
.
params
||
{};
const
data
=
config
.
data
||
false
;
formatDate
&&
data
&&
!
isString
(
data
)
&&
formatRequestDate
(
data
);
if
(
config
.
method
?.
toUpperCase
()
===
RequestEnum
.
GET
)
{
if
(
config
.
method
?.
toUpperCase
()
===
RequestEnum
.
GET
)
{
if
(
!
isString
(
params
))
{
if
(
!
isString
(
params
))
{
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
...
@@ -102,10 +105,19 @@ const transform: AxiosTransform = {
...
@@ -102,10 +105,19 @@ const transform: AxiosTransform = {
}
else
{
}
else
{
if
(
!
isString
(
params
))
{
if
(
!
isString
(
params
))
{
formatDate
&&
formatRequestDate
(
params
);
formatDate
&&
formatRequestDate
(
params
);
config
.
data
=
params
;
if
(
Reflect
.
has
(
config
,
'
data
'
)
&&
config
.
data
&&
Object
.
keys
(
config
.
data
).
length
>
0
)
{
config
.
params
=
undefined
;
config
.
data
=
data
;
config
.
params
=
params
;
}
else
{
// 非GET请求如果没有提供data,则将params视为data
config
.
data
=
params
;
config
.
params
=
undefined
;
}
if
(
joinParamsToUrl
)
{
if
(
joinParamsToUrl
)
{
config
.
url
=
setObjToUrlParams
(
config
.
url
as
string
,
config
.
data
);
config
.
url
=
setObjToUrlParams
(
config
.
url
as
string
,
Object
.
assign
({},
config
.
params
,
config
.
data
)
);
}
}
}
else
{
}
else
{
// 兼容restful风格
// 兼容restful风格
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment