This behaviour has been added to axios
starting with version 1.0.0
. See paramsSerializer.indexes
at https://github.com/axios/axios/tree/v1.0.0#request-config
Here's an example using your sample code:
axios.get('/myController/myAction', {
params: { storeIds: [1,2,3] },
paramsSerializer: {
indexes: true, // use brackets with indexes
}
)
The resulting query params will have indexes inside the brackets:
/myController/myAction?storeIds[0]=1&storeIds[1]=2&storeIds[2]=3
Other paramsSerializer.indexes
values are null
(no brackets):
axios.get('/myController/myAction', {
params: { storeIds: [1,2,3] },
paramsSerializer: {
indexes: null, // no brackets at all
}
)
// /myController/myAction?storeIds=1&storeIds=2&storeIds=3
And the default false
(brackets without indexes):
axios.get('/myController/myAction', {
params: { storeIds: [1,2,3] },
paramsSerializer: {
indexes: false, // brackets but no indexes
}
)
// /myController/myAction?storeIds[]=1&storeIds[]=2&storeIds[]=3
[]
still work? – Twilatwilight