refactor: axios 请求拦截器优化

Former-commit-id: d74d1bed56567aba2a0aafa4497c6c3682be6ef9
This commit is contained in:
haoxr
2023-03-16 01:10:44 +08:00
parent 6e1eccc9c0
commit 71811d652a

View File

@@ -11,14 +11,9 @@ const service = axios.create({
// 请求拦截器
service.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
if (!config.headers) {
throw new Error(
`Expected 'config' and 'config.headers' not to be undefined`
);
}
const user = useUserStoreHook();
if (user.token) {
config.headers.Authorization = localStorage.getItem('accessToken');
const userStore = useUserStoreHook();
if (userStore.token) {
config.headers.Authorization = userStore.token;
}
return config;
},