最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vuejs get token from header - Stack Overflow

programmeradmin2浏览0评论

I have a response from server and there are auth token, max age and some other values. In Postman it looks like:

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);
        })

but there is an error:

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

how it it possible to read my token from header?

I have a response from server and there are auth token, max age and some other values. In Postman it looks like:

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);
        })

but there is an error:

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

how it it possible to read my token from header?

Share Improve this question asked Mar 5, 2017 at 18:28 littlewombatlittlewombat 3092 gold badges8 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

Use headers

response.headers.get('Authorization');
发布评论

评论列表(0)

  1. 暂无评论