dee8c762 by renchao@pashanhoo.com

style:token设置

1 parent 1a2d8aba
/*
* @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
* @Autor: renchao
* @LastEditTime: 2023-05-31 15:30:02
* @LastEditTime: 2023-06-01 09:20:24
*/
import axios from 'axios'
import { Message } from 'element-ui'
......@@ -10,9 +10,9 @@ import { endLoadingSubCount } from './requestLoading'
// create an axios instance
const service = axios.create({
baseURL:
process.env.NODE_ENV == "development"
? process.env.VUE_APP_BASE_API
: window.baseUrl + "/",
process.env.NODE_ENV == "development"
? process.env.VUE_APP_BASE_API
: window.baseUrl + "/",
withCredentials: true, //是否允许跨域
headers: {
'Content-Type': 'application/json; charset=utf-8'
......@@ -38,7 +38,7 @@ service.interceptors.request.use(
return Promise.reject(error);
}
)
window.__isNeedLogin = true
// response interceptor
service.interceptors.response.use(
response => {
......@@ -60,7 +60,7 @@ service.interceptors.response.use(
//todo: 需要解决 一个页面多个请求,刷新后此处会触发多次
if (window.__isNeedLogin) {
window.__isNeedLogin = false
this.$message.error('token失效,请重新登录');
Message.error('token失效,请重新登录');
let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
localStorage.removeItem('token')
if (window._config.casEnable) {
......