The Vue post request reports an error because the background requires the data to be in form-data format

Need to use the qs plugin to serialize the parameters
1, install

npm install qs --save

2. Introduce in main.js

import Qs from 'qs'
Vue.prototype.qs = Qs

3. Use

var this=_this
let data = {
    
     batchNum: _this.pcNumnow };//要传给后端的参数
_this.$http.post('/index/grade/', _this.$qs.stringify(data)).then(function(res) {
    
    
        console.log('这是返回的数据');
        console.log(res.data);
});

Guess you like

Origin blog.csdn.net/GongWei_/article/details/110393273