【问题标题】:How to pass queries using Axios in Vue如何在 Vue 中使用 Axios 传递查询
【发布时间】:2020-11-07 03:24:25
【问题描述】:

如何使用 Axios 传递查询参数,以便可以使用 req.query.email 在后端代码中获取查询。这似乎不起作用:

this.$http.post(this.$BASE_URL + 'agents/auth/create-password', {
  data: { password: this.password },
  params: {
    email,
  },
})
.then((res) => {
  console.log(res);
})
.catch((error) => {
  console.log(error);
})

我从我的 api 得到的是 req.body.datareq.body.params

【问题讨论】:

  • 基于this.$http 我不认为您使用的是axios,而是使用vue-resource。请阅读github.com/pagekit/vue-resource/blob/master/docs/http.md
  • 我用的是axios,只是用了我在main.js中设置的原型
  • 很抱歉得出紧急结论。你能发布更多关于该实现的代码吗?因为参数可能有问题。
  • 您还需要了解哪些额外的实现?我在上面解释了我想做什么
  • 我想知道你是如何实现 this.$http 的,它包裹 axios 或者你只是使用 Vue.prototype.$http = axios

标签: javascript node.js express vue.js axios


【解决方案1】:
const querystring = require('querystring');
axios.post('http://something.com/', querystring.stringify({ foo: 'bar' }));

欲了解更多信息,请查看https://github.com/axios/axios#query-string

【讨论】:

    猜你喜欢
    • 2018-08-05
    • 2019-05-11
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 2017-10-19
    • 2021-12-19
    相关资源
    最近更新 更多