The post in the Axios is particularly large in a pit.

Source: Internet
Author: User

In jquery, Ajax requests to send post are convenient, but in Vue projects, the introduction of jquery is no longer appropriate.

var  This var data = {    filter:'-_id '}$.ajax ({        URL:' http://localhost:3000/api/goods/get ') ,        type:' post ',        data:data,        dataType:' json ',        success:  function(res) {          =res.data        }      )

There are two places to pay great attention to post requests in Axios:

To set the appropriate request header, generally use x-www-form-urlencoded can

Send the data to serialize, pay special attention to Ah, because the Axios default format is the request Payload.

Axios.post (' Http://localhost:3000/api/goods/get ', qs.stringify (data), {        headers: {            ' Content-type ': ' application/x-www-form-urlencoded; Charset=utf-8 '          }      }). Then (res        = = res.data              = { Console.log (Err)      })

wherein the QS module is a package into the Axios module,

When introducing Axios, QS can be introduced simultaneously.

Such as:

Import Axios from ' Axios ' import qs from ' QS '

  

The post in the Axios is particularly large in a pit.

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.