来自qs
,我们将使用arrayFormat
选项控制查询参数中的数组的方式(引用下面的qs
文档):
You may use the arrayFormat option to specify the format of the output array:
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }) // 'a[0]=b&a[1]=c' qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }) // 'a[]=b&a[]=c' qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }) // 'a=b&a=c' qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' }) // 'a=b,c'
我们如何使用URLSearchParams
控制格式?
正在做:
new URLSearchParams({ a: ['b', 'c']})
总是给出a=b,c
。
最佳答案
你不能。这不是 URLSearchParams
的功能。
如果您需要该功能,请改用qs
。
关于javascript - URLSearchParams 中的 arrayFormat 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58452823/