javascript 将 Axios.Get 与 params 和 config 一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48261227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use Axios.Get with params and config together
提问by KitKit
How do I use axios.getwith params and config together? My code is not working. Please help me this basic issue!
如何axios.get与 params 和 config 一起使用?我的代码不起作用。请帮我解决这个基本问题!
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
})
回答by casraf
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:
Axios 在第二个参数中获取整个配置,而不是配置对象列表。将参数放在配置中,并将整个对象作为第二个参数传递:
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)
回答by Biswajit Patra
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:
文档:

