【问题标题】:Unable to add Axios Default Headers to VueJS app无法将 Axios 默认标头添加到 VueJS 应用程序
【发布时间】:2020-11-04 05:33:09
【问题描述】:

我试过了

axios.defaults.headers.common['X-CSRF-TOKEN'] = 'test';
axios.defaults.headers.common['Authenticaton'] = 'Bearer slskdf';

在我的路由器文件中的 ma​​in.jsindex.js 中,beforeEach.....根本没有标题出现在浏览器中。

让这些标头出现在每次通话中我做错了什么?

谢谢

【问题讨论】:

    标签: vue.js axios http-headers jwt


    【解决方案1】:

    从 0.19 版开始,如果您创建 axios 实例来发出请求,axios 将不再使用 axios.defaults。为实例设置默认值并使用它来发出请求。

    const adapter = axios.create({
        baseURL: 'http://localhost:8080/my-api',
        headers: {
            Accept: 'application/json;charset=UTF-8',
        },
    });
    adapter.defaults.headers.common['Authorization'] = 'Bearer test';
    adapter.get(...)
    
    See [this issue][1] and [related pull request][1]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      相关资源
      最近更新 更多