将 Axios.Get 与参数和配置一起使用
Use Axios.Get with params and config together
如何将 axios.get
与参数和配置一起使用?我的代码不工作。请帮我解决这个基本问题!
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 在第二个参数中获取整个配置,而不是配置对象列表。将参数放入配置中,并将整个对象作为第二个参数传递:
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)
如果您想传递自定义 header 您可以通过
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
})
请按照文档查看任何进一步的要求,或者您也可以在这里发表评论。
也试试这个:
var config = {
headers: {'Authorization': 'JWT ' + this.$store.state.token}
};
axios.get('http://localhost:8000/api/v1/f/',{
params: {
page: f + 1
}}, config);
文档:
如何将 axios.get
与参数和配置一起使用?我的代码不工作。请帮我解决这个基本问题!
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 在第二个参数中获取整个配置,而不是配置对象列表。将参数放入配置中,并将整个对象作为第二个参数传递:
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)
如果您想传递自定义 header 您可以通过
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
})
请按照文档查看任何进一步的要求,或者您也可以在这里发表评论。
也试试这个:
var config = {
headers: {'Authorization': 'JWT ' + this.$store.state.token}
};
axios.get('http://localhost:8000/api/v1/f/',{
params: {
page: f + 1
}}, config);
文档: