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

Bug: 请求传入数组的时候,会有[]出现导致请求出错 #5320

Closed
5 tasks done
bo-Chou opened this issue Jan 7, 2025 · 5 comments
Closed
5 tasks done

Bug: 请求传入数组的时候,会有[]出现导致请求出错 #5320

bo-Chou opened this issue Jan 7, 2025 · 5 comments

Comments

@bo-Chou
Copy link

bo-Chou commented Jan 7, 2025

Version

Vben Admin V5

Describe the bug?

接口如下,调用的时候会追加上[]导致请求异常。
`/**

  • delete role user
    */
    export async function deleteRoleUserApi(ids: string[]) {
    return requestClient.delete('/role/delete-user', { params: { ids } });
    }
    `

Reproduction

Uploading image.png…
`/**

  • delete role user
    */
    export async function deleteRoleUserApi(ids: string[]) {
    return requestClient.delete('/role/delete-user', { params: { ids } });
    }
    `

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i9-13900H
    Memory: 7.25 GB / 31.66 GB
  Binaries:
    Node: 20.17.0 - D:\Software\nodejs\node.EXE
    npm: 10.8.3 - D:\Software\nodejs\npm.CMD
    pnpm: 9.15.2 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.26100.1882

Relevant log output

No response

Validations

@RanMaoting
Copy link

get请求吗,get请求默认不能使用array,需要特殊处理,或者跟后端约定好直接传字符串

@bo-Chou
Copy link
Author

bo-Chou commented Jan 8, 2025

get请求吗,get请求默认不能使用array,需要特殊处理,或者跟后端约定好直接传字符串

delete请求,只不过是拼接字符串,我看有个参数 :paramsSerializer 这里应该怎么配置呢

@RanMaoting
Copy link

这个估计要看axios的文档怎么说了,我们在项目中这种比较复杂的参数一般选择在body里面传递,而不是通过?来传
最简单的就是让后端给你放在body里面传

@bo-Chou
Copy link
Author

bo-Chou commented Jan 8, 2025

这个估计要看axios的文档怎么说了,我们在项目中这种比较复杂的参数一般选择在body里面传递,而不是通过?来传 最简单的就是让后端给你放在body里面传

我搜索到可以使用qs来格式化,两种都行

@bo-Chou bo-Chou closed this as completed Jan 8, 2025
@bo-Chou
Copy link
Author

bo-Chou commented Jan 8, 2025

这个估计要看axios的文档怎么说了,我们在项目中这种比较复杂的参数一般选择在body里面传递,而不是通过?来传 最简单的就是让后端给你放在body里面传

/**

  • delete role user
    */
    export async function deleteRoleUserApi(ids: string[]) {
    return requestClient.delete('/role/delete-user', {
    params: { ids },
    paramsSerializer: {
    indexes: null,
    },
    });
    }
    // 这样写也可以好像

@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants