2017-03-05 77 views
3

我有一個來自服務器的響應,並且有auth令牌,最大年齡和一些其他值。在郵差它看起來像: enter image description hereVuejs從頭部獲取令牌

我想將它設置爲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 

它如何從標頭中讀取我的令牌?

回答

1

使用headers

response.headers.get('Authorization'); 
+0

不幸'的console.log(response.headers.get( '授權'))'返回null – littlewombat

+1

@littlewombat確定授權是回來了嗎?以下是獲取不同標題的示例。 http://codepen.io/Kradek/pen/EWyBXM?editors=1010 – Bert