优化JWT token获取和请求

This commit is contained in:
sakuya 2021-07-10 13:18:11 +08:00
parent 6ffcec2150
commit 1f246c6f9a
2 changed files with 10 additions and 2 deletions

View File

@ -10,7 +10,10 @@ const DEFAULT_CONFIG = {
//MOCK接口地址
MOCK_URL: "https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api",
//TokenName
TOKEN_NAME: "Authorization",
//布局 默认default | 通栏header | 经典menu | 功能坞dock
//dock将关闭标签和面包屑栏
LAYOUT: 'default',

View File

@ -1,5 +1,7 @@
import axios from 'axios';
import { ElNotification } from 'element-plus';
import sysConfig from "@/config";
import tool from '@/utils/tool';
axios.defaults.baseURL = ''
@ -8,7 +10,10 @@ axios.defaults.timeout = 10000
// HTTP request 拦截器
axios.interceptors.request.use(
(config) => {
config.headers['Authorization'] = "SCUI-Demo-Auth"
let userInfo = tool.data.get("user");
if(userInfo){
config.headers[sysConfig.TOKEN_NAME] = userInfo.token
}
return config;
},
(error) => {