Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios请求格式化请求参数一个小问题 #850

Closed
colinin opened this issue Jul 3, 2021 · 3 comments
Closed

Axios请求格式化请求参数一个小问题 #850

colinin opened this issue Jul 3, 2021 · 3 comments

Comments

@colinin
Copy link

colinin commented Jul 3, 2021

不知道怎么描述,直接贴出问题点所在吧,在beforeRequestHook中对于所有非GET请求参数进行格式化,如果没有传递params参数,例如 POSTPUT请求,那么传递的data数据会被覆盖

https://github.com/anncwb/vue-vben-admin/blob/8819af083c80389453153c2b5f84b3bd1e408ba5/src/utils/http/axios/index.ts#L103-L110

问题复现:

import { defHttp } from '/@/utils/http/axios';
defHttp.put({
 data: { value: 1 },
 url: 'http://localhost:8080'
})

此时观察控制台网络请求,请求体中Request Payload为空

image

@mynetfan
Copy link
Collaborator

mynetfan commented Jul 3, 2021

所有的参数一律通过params提交,无论是GET还是POST、PUT。如果有params以及data同时存在的场景,请自己按照defHttp的参考简单封装一个axios实例。

@colinin
Copy link
Author

colinin commented Jul 3, 2021

OK,理解错了项目中axios的逻辑

@colinin colinin closed this as completed Jul 3, 2021
@mynetfan
Copy link
Collaborator

mynetfan commented Jul 3, 2021

修改了一下你提到的地方,保持原用法不变,但是兼容你说的用法。非GET请求时,如果同时存在data和params,不会丢弃data数据;如果只存在params,仍然像之前那样会被视作data。

mynetfan added a commit that referenced this issue Jul 3, 2021
当非GET请求并且同时存在data和params,不再忽略data。使defHttp的用法习惯接近axios原生配置

fixed: #850
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants