The input parameters of the axios request are in the form of objects in the array, which is not as expected after being converted with qs.stringify ().

there are post request parameters like this

requestObj = {
   staffList: [{
       staffId: "xxx",
       availableQuota: 10
   }, {
       staffId": "xxx",
       availableQuota: 14
   }]
}

axios({
    method: "post",
    url: url,
    data: qs.stringify(requestObj, {arrayFormat: "brackets"})
})
After

processing, it becomes like this, like a two-dimensional array

what I hope is

staffList[0].staffId: "xxx"
staffList[0].availableQuota: 10
staffList[1].staffId: "xxx"
staffList[1].availableQuota: 14
Apr.25,2021

requestObj use JSON.stringify () to see


first serialize the array staffList with JSON.stingify (), and then use qs.stringify


answer: with the help of colleagues, Read the document: qs.stringify (data, {arrayFormat: 'indices', allowDots: true}) ,
you can generate the format I need


if the background interface receives an array, there is a simpler way without qs, data can directly send staffList, that is, remove the outer curly braces.

Menu