axiospost requests to submit data to the backend

The reason why Axios submits data to the backend is not easy to receive is that the parameter transmission method is request payload, and the parameter format is json , instead of using form to pass parameters, so the parameters received by receiving form data in the background cannot be received. When the post form request is submitted, the Content-Type used is application/x-www-form-urlencoded , and the POST request using native AJAX does not specify

Set the request header RequestHeader , the default Content-Type is text/plain;charset=UTF-8 .

So take the following solution 

Install qs: npm install qs --save    Reference qs in the page: var qs = require('qs'); At the same time, you need to change the request header headers to:  'Content-Type': 'application/x-www-form-urlencoded ', 

 

Axios sends the request code is, datas is a json data

  1. let postData=this.$qs.stringify(datas)
  2.          console.log(postData)
  3.          this.$axios({
  4.           method: 'post',
  5.           url:'/api/productInfo/insert',
  6.           data:postData
  7.         }).then((res)=>{
  8.             console.log(res)
  9.        });

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325691057&siteId=291194637