The------Transformrequest method, which was mentioned in the previous article, also parses the array into strings to be passed to the background.
So how do you avoid this problem?
(i) convert an array to a JSON string
Convert to a JSON string by json.stringify () so that the backend is converted to an array after it is received.
This method can basically solve most of the situation.
(b) Add the array through append formdata.
We are in the Python language, using the Django framework, and when I send it through the first method, he adds the JSON string as a whole to an array, for example:
[1,2,3,4,5]/* through Json.stringify () after conversion, backstage will get the array */[' [1,2,3,4,5] ']
So the docking failed.
The point here is thatPython supports a single-key multivalued case where a key can correspond to more than one value and put more than one value into an array.
var params = new Urlsearchparams (); for (var key in opt.obj) { if (Array.isarray (Opt.obj[key])) {for (Var val in Opt.obj[key]) { params.append ( Key, Opt.obj[key][val]); } } else{ params.append (Key,opt.obj[key]) } }
Take advantage of this Python feature. Through Urlsearchparams, docking success ~
---pass-through array (supplemental) for post-request-to-parameter problems in Vue:axios