简体   繁体   中英

Use Axios.Get with params and config together

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

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) 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM