Browse Source

feat:根据环境请求不同后端地址

liyangbin 1 year ago
parent
commit
86b9a4b7ae
5 changed files with 9 additions and 4 deletions
  1. 1 0
      .env
  2. 1 0
      .env.preparing
  3. 1 0
      .env.production
  4. 3 2
      package.json
  5. 3 2
      utils/request.js

+ 1 - 0
.env

@@ -0,0 +1 @@
+VITE_BASE_URL = http://124.223.7.184:8032

+ 1 - 0
.env.preparing

@@ -0,0 +1 @@
+VITE_BASE_URL = http://124.223.7.184:8032

+ 1 - 0
.env.production

@@ -0,0 +1 @@
+VITE_BASE_URL = https://console.pdfreaderpro.com

+ 3 - 2
package.json

@@ -2,8 +2,9 @@
   "name": "pdf_tech_front_end",
   "version": "0.0.0",
   "scripts": {
-    "dev": "vite",
-    "build": "vite build",
+    "dev": "vite --mode development",
+    "preparing": "vite --mode preparing build",
+    "build": "vite --mode production build",
     "preview": "vite preview --port 4173",
     "test:unit": "vitest --environment jsdom",
     "test:e2e": "start-server-and-test preview http://localhost:4173/ 'cypress open --e2e'",

+ 3 - 2
utils/request.js

@@ -2,15 +2,16 @@ import axios from 'axios';
 import cookies from 'vue-cookies'
 import { userStore } from '@/store/userInfo'
 import { Message } from 'element-ui'
-import Qs from 'qs'
 
 //关闭断网时toast
 let msg = {
   close(){}
 }
+console.log(' env: ',  import.meta.env);
+
 // 创建请求实例
 const instance = axios.create({
-  baseURL: 'http://124.223.7.184:8032',
+  baseURL: import.meta.env.VITE_BASE_URL,
   // 指定请求超时的毫秒数
   timeout: 10000,
   // 表示跨域请求时是否需要使用凭证