优化全局配置
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
# 开发环境
|
||||
VITE_APP_BASE_API = '/api'
|
||||
VITE_APP_BASE_API='/api'
|
||||
|
||||
|
||||
VITE_APP_BASE_URL='http://192.168.1.38:18081'
|
||||
@@ -1,2 +1,4 @@
|
||||
# 生产环境
|
||||
VITE_APP_BASE_API = '/prod-api'
|
||||
VITE_APP_BASE_API=/prod-api
|
||||
|
||||
VITE_APP_BASE_URL=http://127.0.0.1:18081
|
||||
1
global.d.ts
vendored
1
global.d.ts
vendored
@@ -2,4 +2,3 @@
|
||||
declare module '@/components/*';
|
||||
declare module '@/views/*';
|
||||
declare module '@/api/*';
|
||||
declare module '@/App.vue';
|
||||
|
||||
@@ -13,7 +13,7 @@ const errCodeMap: { [key: string]: string } = {
|
||||
|
||||
// 创建axios实例
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API as string,
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ service.interceptors.request.use(
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
console.log(response)
|
||||
// console.log(response);
|
||||
const code = response.data.code || 200;
|
||||
const data = response.data;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import Components from "unplugin-vue-components/vite"; // 按需组件自动导入
|
||||
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
@@ -7,7 +7,11 @@ import IconsResolver from 'unplugin-icons/resolver';
|
||||
import path from 'path';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
export default defineConfig(({ mode }) => {
|
||||
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
|
||||
return {
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "src"),
|
||||
@@ -16,12 +20,12 @@ export default defineConfig({
|
||||
server: {
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://192.168.1.38:18081",
|
||||
target: env.VITE_APP_BASE_URL,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||
},
|
||||
"/prod-api": {
|
||||
target: "http://127.0.0.1:18081",
|
||||
target: env.VITE_APP_BASE_URL,
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
@@ -47,4 +51,5 @@ export default defineConfig({
|
||||
autoInstall: true, // 没安装的图标库会自动下载
|
||||
}),
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user