diff --git a/.env.development b/.env.development
index 5c3cf8d..dafeb3c 100644
--- a/.env.development
+++ b/.env.development
@@ -1,2 +1,5 @@
# 开发环境
-VITE_APP_BASE_API = '/api'
\ No newline at end of file
+VITE_APP_BASE_API='/api'
+
+
+VITE_APP_BASE_URL='http://192.168.1.38:18081'
\ No newline at end of file
diff --git a/.env.production b/.env.production
index c75f02a..a2d8567 100644
--- a/.env.production
+++ b/.env.production
@@ -1,2 +1,4 @@
# 生产环境
-VITE_APP_BASE_API = '/prod-api'
\ No newline at end of file
+VITE_APP_BASE_API=/prod-api
+
+VITE_APP_BASE_URL=http://127.0.0.1:18081
\ No newline at end of file
diff --git a/global.d.ts b/global.d.ts
index bc8a495..36160f9 100644
--- a/global.d.ts
+++ b/global.d.ts
@@ -1,5 +1,4 @@
// declare module '@/*';
declare module '@/components/*';
declare module '@/views/*';
-declare module '@/api/*';
-declare module '@/App.vue';
+declare module '@/api/*';
\ No newline at end of file
diff --git a/src/api/request.ts b/src/api/request.ts
index 174ccc3..a960bbc 100644
--- a/src/api/request.ts
+++ b/src/api/request.ts
@@ -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;
diff --git a/vite.config.ts b/vite.config.ts
index 7b19189..ba80cf2 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -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,44 +7,49 @@ import IconsResolver from 'unplugin-icons/resolver';
import path from 'path';
// https://vite.dev/config/
-export default defineConfig({
- resolve: {
- alias: {
- "@": path.resolve(__dirname, "src"),
- },
- },
- server: {
- proxy: {
- "/api": {
- target: "http://192.168.1.38:18081",
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, ""),
- },
- "/prod-api": {
- target: "http://127.0.0.1:18081",
- changeOrigin: true,
+export default defineConfig(({ mode }) => {
+
+ const env = loadEnv(mode, process.cwd());
+
+ return {
+ resolve: {
+ alias: {
+ "@": path.resolve(__dirname, "src"),
},
},
- },
- plugins: [
- vue(),
- Components({
- dts: true, //生成components.d.ts 全局定义文件
- resolvers: [
- AntDesignVueResolver({
- //对使用到的全局ant design vue组件进行类型导入
- importStyle: false, // 不动态引入css,这个不强求
- }),
- // 自动导入 lucide 图标
- IconsResolver({
- prefix: "i", // 比如用
- enabledCollections: ["lucide"],
- }),
- ],
- include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型
- }),
- Icons({
- autoInstall: true, // 没安装的图标库会自动下载
- }),
- ],
+ server: {
+ proxy: {
+ "/api": {
+ target: env.VITE_APP_BASE_URL,
+ changeOrigin: true,
+ rewrite: (path) => path.replace(/^\/api/, ""),
+ },
+ "/prod-api": {
+ target: env.VITE_APP_BASE_URL,
+ changeOrigin: true,
+ },
+ },
+ },
+ plugins: [
+ vue(),
+ Components({
+ dts: true, //生成components.d.ts 全局定义文件
+ resolvers: [
+ AntDesignVueResolver({
+ //对使用到的全局ant design vue组件进行类型导入
+ importStyle: false, // 不动态引入css,这个不强求
+ }),
+ // 自动导入 lucide 图标
+ IconsResolver({
+ prefix: "i", // 比如用
+ enabledCollections: ["lucide"],
+ }),
+ ],
+ include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型
+ }),
+ Icons({
+ autoInstall: true, // 没安装的图标库会自动下载
+ }),
+ ],
+ }
});