|
@@ -2,6 +2,7 @@ import axios from "axios";
|
|
import { showMessage } from "./errorStatusCode"; // 引入状态码文件
|
|
import { showMessage } from "./errorStatusCode"; // 引入状态码文件
|
|
import type { AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
|
|
import type { AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
|
|
import { ElNotification } from "element-plus";
|
|
import { ElNotification } from "element-plus";
|
|
|
|
+import { useStore } from "../store/index";
|
|
const baseURL = "/api";
|
|
const baseURL = "/api";
|
|
// 创建axios实例
|
|
// 创建axios实例
|
|
const instance = axios.create({
|
|
const instance = axios.create({
|
|
@@ -12,8 +13,10 @@ const instance = axios.create({
|
|
instance.interceptors.request.use(
|
|
instance.interceptors.request.use(
|
|
(config: AxiosRequestConfig): any => {
|
|
(config: AxiosRequestConfig): any => {
|
|
// 可在请求发送前对config进行修改,如添加请求头等
|
|
// 可在请求发送前对config进行修改,如添加请求头等
|
|
|
|
+ const { getToken } = useStore()
|
|
|
|
+ const token = getToken
|
|
const headers = config.headers || {};
|
|
const headers = config.headers || {};
|
|
- headers["Authorization"] = "Bxxx";
|
|
|
|
|
|
+ headers["Token"] = token;
|
|
config.headers = headers;
|
|
config.headers = headers;
|
|
return config;
|
|
return config;
|
|
},
|
|
},
|