直接放在对象中传递数组,传递的参数格式如下:
但是这样的话后台是取不到值的,我们需要把数组变成如下这种格式:
test:111
test:222
get / delete请求
axios.get(url, {
params: {
test: [1,2,3],
type: 1
},
paramsSerializer: params => {
return qs.stringify(params, { indices: false })
}})
axios.delete(url, {
params: {
test: [1,2,3],
type: 1
},
paramsSerializer: params => {
return qs.stringify(params, { indices: false })
}})
post / put 请求
axios.post(url, qs.stringify(
params: {
test: [1,2,3],
type: 1
}, { indices: false }))
axios.put(url, qs.stringify(
params: {
test: [1,2,3],
type: 1
}, { indices: false }))
//形式1: test=1&test=2&test=3
qs.stringify({ids: [1, 2, 3]}, { indices: false })
//形式2: test[0]=1&test[1]=2&test[2]=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'indices'})
//形式3: test[]=1&test[]=2&test[]=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'brackets'})
//形式4: test=1&test=2&test=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'repeat'})