Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 자료구조
- EBS
- .getClass()
- 오라클
- 리덕스 공식문서
- Java Reflextion API
- forNmae()
- REDIS
- rabbitmq 에러
- redux
- ACCESS_REFUSED
- exiting abnormally
- 커스텀 로그인
- 자바
- 도커빌드
- 애그리거트
- $emit()
- react
- paraller
- 리덕스
- 네임드 뷰
- 오라클 병렬처리
- AWS
- vue.js
- quert
- Express
- 공식문서
- 컴포넌트 주도
- VUE
- 리액트
Archives
- Today
- Total
개발정리
[트러블 슈팅] vue.js axios 인터셉터 설정 본문
이때 까지는 항상 컴포넌트 마다 axios를 임포트 해와서 CRUD를 구현 해 왔다.
하지만 그때마다 요청의 헤더에 토큰을 주입해서 전달하기 여간 귀찮은 일이 아닙니다.
그래서 찾아보던중 axios의 인터셉터 설정을 하면 요청마다 일일이 토큰을 주입하지 않아도 된다는 것을 알게되었습니다.
해결
import { createApp } from 'vue'
import router from './index.js'
import App from './App.vue'
import mitt from 'mitt';
import axios from 'axios';
axios.interceptors.request.use((config)=>{
const token = localStorage.getItem('token');
if(token){
config.headers.Authorization=`Bearer ${token}`
}
return config;
});
const emitter = mitt();
const app=createApp(App);
app.config.globalProperties.emitter=emitter;
app.config.globalProperties.$axios=axios;
app.use(router);
app.mount('#app');
main.js 파일에 axios를 설정해 주었습니다.
'개발 > 중거거래사이트 클론' 카테고리의 다른 글
[트러블 슈팅] Cannot read properties of undefined (reading 'userId') (0) | 2024.02.23 |
---|---|
[트러블 슈팅]-라우터 params undefined 문제 (0) | 2024.02.20 |
[트러블 슈팅] jpa 양방향 매핑 조회시 stackoverflow 문제 (0) | 2024.02.18 |
[트러블 슈팅]로그인시 로그아웃으로 변경 (0) | 2024.02.05 |
[BUG] 415 (Unsupported Media) error (0) | 2024.02.03 |