Vuejs 从标题中获取令牌 [英] Vuejs get token from header
本文介绍了Vuejs 从标题中获取令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到了来自服务器的响应,其中包含身份验证令牌、最大年龄和其他一些值.在邮递员中,它看起来像:
I have a response from server and there are auth token, max age and some other values. In Postman it looks like:
我想将其设置为 localStorage 但不知道如何在 vuejs 文件中获取值,我尝试了以下代码:
I want to set it to localStorage but have no idea how to get value in vuejs file, I tried this code:
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
如何从标题中读取我的令牌?
how it it possible to read my token from header?
推荐答案
使用 标题
response.headers.get('Authorization');
这篇关于Vuejs 从标题中获取令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文