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

Get请求时 传键值对无法解析 #369

Open
ByteXiong opened this issue May 26, 2024 · 7 comments
Open

Get请求时 传键值对无法解析 #369

ByteXiong opened this issue May 26, 2024 · 7 comments
Labels
bug:confirmed Something isn't working Vue Issues or pull request for Vue

Comments

@ByteXiong
Copy link

ByteXiong commented May 26, 2024

请详细描述bug

get传参{ keyWord:"", sortList: { sort: 'desc' }}
在Axios中 get url: ?keyWord=&sortList[sort]=desc
在alova中 get url: ?keyWord=&sortList=[object%20Object]

复现链接

No response

复现步骤

get请求传 json 键值对

期望的表现

No response

alova 版本

2.20.5

设备/浏览器/浏览器版本

No response

额外的说明

No response

@ByteXiong ByteXiong added bug:need-confirm It's probably a bug Vue Issues or pull request for Vue labels May 26, 2024
@MeetinaXD
Copy link
Contributor

你好,请提供部分可复现的代码。

@ByteXiong
Copy link
Author

const list = ref([]);
const param = reactive({
pageIndex: 1, //当前页
pageSize: 10, //当前显示
sortList: { sort: 'desc' },
});
const getData = async () => {
let { data } = await get('/api/UserAddress/getMyPage', param, loading);
list.value.push(...data.data);
};

@MeetinaXD
Copy link
Contributor

这看着不是 alova 的用法,你是不是在用 axios 或者其他的库?

@ByteXiong
Copy link
Author

export const get = <T = any>(url: string, params?: T, loading?: Ref) => {
if (loading) loading.value = true;
return useRequest(request.Get(url, { params: params || {} }))
.send()
.finally(() => {
if (loading) loading.value = false;
});
};
我底层封装过, 你get 传一个键值对参数{sortList: { sort: 'desc' }}就能找到问题

@ByteXiong
Copy link
Author

我想解决的问题是 在 http query里怎么才能传键值对

@MeetinaXD
Copy link
Contributor

了解了,原来你说的是嵌套对象下的序列化问题。

这个问题我们复现了。目前你暂时可以通过 qs 来手动序列化 params。

问题修复后我们会在这里回复 :)

@MeetinaXD MeetinaXD added bug:confirmed Something isn't working and removed bug:need-confirm It's probably a bug labels May 27, 2024
@LengGeng
Copy link

我也遇到了类似的问题,现在 alova 的 params 总的数组会被转换成 1,2,3
我本以为 alova是在 adapter 中处理的,但实际上 alova 是在 /src/functions/sendRequest.ts[58] 的 /src/functions/sendRequest.ts 函数中进行了 url 的构建,是否可以像 axios 中 提供类似 paramsSerializer 的配置可以让用户进行配置

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:confirmed Something isn't working Vue Issues or pull request for Vue
Projects
None yet
Development

No branches or pull requests

3 participants