Javascript Vuejs从标头获取令牌
我有一个来自服务器的响应,其中有auth-token、max-age和一些其他值。在《邮递员》中,它看起来像: 我想将其设置为localStorage,但不知道如何在vuejs文件中获取值,我尝试了以下代码:Javascript Vuejs从标头获取令牌,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我有一个来自服务器的响应,其中有auth-token、max-age和一些其他值。在《邮递员》中,它看起来像: 我想将其设置为localStorage,但不知道如何在vuejs文件中获取值,我尝试了以下代码: this.$http.post('http://localhost:8081/login', data) .then(response =>{ console.log(response.header.Authorization);
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
如何从标题读取我的令牌?使用
不幸的是
console.log(response.headers.get('Authorization'))
返回null@littlewombat你确定授权会回来吗?下面是一个获取不同标题的示例。
response.headers.get('Authorization');