vue-resource如何使用data属性来传递参数。

this.$http({
    url: link,
    method: 'get'
    data: arg,
    headers: {
        'Content-Type': 'application/json:charset=UTF-8'
    },
    emulateJSON: true
})
.then() => {}

然后发现arg夹带的参数并不能够被拼接在链接上传递给后端,请教大神上头代码应该如何修改才能传递该参数呢?

clipboard.png

阅读 4k
2 个回答
 // GET /someUrl?foo=bar
  this.$http.get('/someUrl', {params: {foo: 'bar'}, headers: {'X-Custom': '...'}}).then(response => {
    // success callback
  }, response => {
    // error callback
  });

这是vue-resource的官方示例,但是vue-resource貌似已经不经常维护了,并且vue作者yyx推荐使用axios,所以我建议题主也尝试使用axios

axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

上面的是axios的官方示例~任君挑选

get请求使用data传参,并且写成data:{}形式;
post等传参使用params传参,是params:{}形式

推荐使用axios

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