【问题标题】:Vuejs get token from headerVuejs 从标头获取令牌
【发布时间】:2017-07-25 12:48:28
【问题描述】:

我收到了来自服务器的响应,其中包含身份验证令牌、最大年龄和其他一些值。在邮递员中,它看起来像:

我想将其设置为 localStorage 但不知道如何在 vuejs 文件中获取值,我尝试了以下代码:

this.$http.post('http://localhost:8081/login', data)
        .then(response =>{
          console.log(response.header.Authorization);
        })

但是有一个错误:

Uncaught (in promise) TypeError: Cannot read property 'Authorization' of undefined

如何从标头中读取我的令牌?

【问题讨论】:

    标签: javascript vue.js vuejs2


    【解决方案1】:

    使用headers

    response.headers.get('Authorization');
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-22
    • 2020-11-16
    • 2018-07-26
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多