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
-
let postData=this.$qs.stringify(datas)
-
console.log(postData)
-
this.$axios({
-
method: 'post',
-
url:'/api/productInfo/insert',
-
data:postData
-
}).then((res)=>{
-
console.log(res)
-
});