Vue post请求报错,原因是后台要求数据为form-data格式

需要使用qs插件将参数序列化
1、安装

npm install qs --save

2、在main.js引入

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

3、使用

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);
});

猜你喜欢

转载自blog.csdn.net/GongWei_/article/details/110393273
今日推荐