Use Axios.Get with params and config together

微笑、不失礼 提交于 2019-12-08 10:14:16

问题


How do I use axios.get with params and config together? My code is not working. Please help me this basic issue!

let config = {
    'headers': {'Authorization': 'JWT ' + this.$store.state.token}
}
let f = 0

axios.get('http://localhost:8000/api/v1/f/', {
    params: {
        page: f + 1
    },
    config: this.config
})

回答1:


Axios takes the entire config in the second argument, not a list of config objects. Put the params inside the config, and pass the entire object as the second argument:

let f = 0

let config = {
  headers: {'Authorization': 'JWT ' + this.$store.state.token},
  params: {
    page: f + 1
  },
}

axios.get('http://localhost:8000/api/v1/f/', config)



回答2:


If you want to pass a custom header you can do so by

var config = {
    'Authorization': 'JWT ' + this.$store.state.token
}
let f = 0

axios.get('http://localhost:8000/api/v1/f/', {
    params: {
        page: f + 1
    },
    headers: config
})

Please follow the documentation to so see any further requirements, or you can comment here too.

Try this out too:

var config = {
    headers: {'Authorization': 'JWT ' + this.$store.state.token}
};

axios.get('http://localhost:8000/api/v1/f/',{
    params: {
        page: f + 1
    }}, config);

Documention:

  1. http://codeheaven.io/how-to-use-axios-as-your-http-client/

  2. I can't do a request that needs to set a header with axios

  3. https://github.com/axios/axios



来源:https://stackoverflow.com/questions/48261227/use-axios-get-with-params-and-config-together

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!