[ Update ] : 修正 http header 統一由攔截器去加入以及回傳資料改為 response.data
| | |
| | | service.interceptors.request.use( |
| | | (config:AxiosRequestConfig)=>{ |
| | | loadingStart(); |
| | | addHttpHeader(config); |
| | | return config; |
| | | } |
| | | ); |
| | |
| | | service.interceptors.response.use( |
| | | (response:AxiosResponse)=>{ |
| | | loadingFinish(); |
| | | return response; // maybe can use response.data |
| | | return response.data; |
| | | }, |
| | | (error:AxiosError)=>{ |
| | | loadingFinish(); |
| | |
| | | } |
| | | ); |
| | | |
| | | function addHttpHeader(config: AxiosRequestConfig): void { |
| | | config.headers = { |
| | | Authorization: 'Bearer ' + localStorage.getItem('id_token') |
| | | } |
| | | } |
| | | |
| | | function loadingStart(): void { |
| | | window.$nuxt.$loading.start(); |
| | | }; |