结合使用Axios.Get和params并进行配置 [英] Use Axios.Get with params and config together

查看:830
本文介绍了结合使用Axios.Get和params并进行配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将axios.get与params和config一起使用?我的代码无法正常工作.请帮我解决这个基本问题!

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在第二个参数中获取整个配置,而不是配置对象列表.将参数放入配置中,然后将整个对象作为第二个参数传递:

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)

这篇关于结合使用Axios.Get和params并进行配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆