programing

Vuejs 헤더에서 토큰 가져오기

prostudy 2022. 5. 4. 21:25
반응형

Vuejs 헤더에서 토큰 가져오기

나는 서버로부터 응답을 받았으며 인증 토큰, 최대 사용 기간 및 다른 값들이 있다.Postman에서는 다음과 같이 보인다.

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

어떻게 헤더에서 내 토큰을 읽을 수 있을까?

머리글 사용

response.headers.get('Authorization');

참조URL: https://stackoverflow.com/questions/42612255/vuejs-get-token-from-header

반응형