---pass-through array (supplemental) for post-request-to-parameter problems in Vue:axios

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.