用vue-resource请求接口,接口接收不到参数

var app = new Vue({

el: '#app',
data: {
    item: {
        access_token: '3a7a3c4c2cdcaf9e83b887140189d352',
        brand_id: 1,
        venue_id: 1,
        emp_id: 1
    }
},
methods: {
    getCoachInfo: function() {
        var self = this;
        this.$http.post('//121.42.41.228:8011/employee/api/wxcempdetail', this.item).then(
            function(res) {
                if (res.error == 'ok') {
                    self.name = res.data.name;
                } else {
                    alert('error');
                }
            });
    }
}

});
调试工具已经显示向接口传递的参数了,如截图:

clipboard.png
但是接口返回的结果是“信息不完整”:

clipboard.png
应该不是接口的问题,因为我用jQuery的$.post请求成功了,就是“this.item”传递参数这里出了问题,请大神赐教~

阅读 13.7k
5 个回答

请求前加上这段试试

Vue.http.options.emulateJSON = true;

**楼主搞定这个问题了么?求解答啊
get没有任何问题,就vue的post方式参数后台接收 不到。
也加了Vue.http.options.emulateJSON = true; 还是不行**

———————————————————————————————————————————————————————————————————————

补充
可以了
//Vue.http.options.emulateJSON = true;

     var p ={name:"zhangsan",id:"aaaa"}
     this.$http.post("http://localhost:8888/tmgms/vue/postMsg.do",p,{emulateJSON:true}).then(function(r){
                
     })

vue-resource使用post方法,这样是没错的,如果你说的jquery可以的话,可能是某种协议头不一样,例如Content-Type 检查看看

看看后台都有返回了,应该不是请求的问题。你看看协议头一不一样吧。
或者看看后台的代码 是否限制了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进