import axios from 'axios'
import { ElMessage } from 'element-plus'
import {getToken} from "@/utils/Token/index.js";
const service = axios.create({
// axios中请求配置有baseURL选项,表示请求URL公共部分
baseURL: '/api',
// 超时
timeout: 1000 * 60,
headers: {
'Content-Type': 'application/json'
}
})
//请求拦截器
service.interceptors.request.use((config) => {
//如果存在token,请求携带token
const token = getToken();
if (token !== null) {
config.headers['Authorization'] = token;
config.headers['x-control-file-token'] = token;
}
return config;
}, (error) => {
ElMessage.error({ message: error });
})
//响应拦截
service.interceptors.response.use((success) => {
if (success.status === 200) {
return success.data;
}
}, (error) => {
debugger
if (error.response.status === 500) {
ElMessage.error("服务器异常-请联系管理员")
} else {
ElMessage({ message: '该错误触及盲区(●ˇ∀ˇ●)' });
}
});
export default service;
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
//用来配置跨域
host: '127.0.0.1',
port: 8000,
proxy: {
'/api': {
target: 'http://127.0.0.1:10085',//目标服务器地址
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
},
}
}
})