陈少旭 5 months ago
parent
commit
0f51b03b2d
3 changed files with 8 additions and 9 deletions
  1. 1 2
      .env.development
  2. 6 6
      src/http/index.js
  3. 1 1
      src/utils/request.js

+ 1 - 2
.env.development View File

1
 ## base API 开发环境
1
 ## base API 开发环境
2
 # VUE_APP_BASE_API = 'sf.sgjyun.com'
2
 # VUE_APP_BASE_API = 'sf.sgjyun.com'
3
-# VUE_APP_BASE_API = 'http://127.0.0.1:9788'
4
-
5
 # NODE_ENV = 'development' http://127.0.0.1:9788
3
 # NODE_ENV = 'development' http://127.0.0.1:9788
6
 # BASE_URL = "http://localhost:8080/admin-vue/"
4
 # BASE_URL = "http://localhost:8080/admin-vue/"
5
+

+ 6 - 6
src/http/index.js View File

6
 // 创建axios实例
6
 // 创建axios实例
7
 const service = axios.create({
7
 const service = axios.create({
8
   // 'http://127.0.0.1:9788'  process.env.VUE_APP_BASE_API 'sf.sgjyun.com'
8
   // 'http://127.0.0.1:9788'  process.env.VUE_APP_BASE_API 'sf.sgjyun.com'
9
-    // baseURL: process.env.VUE_APP_BASE_API , //URL地址   环境变量文件 
10
-    baseURL: 'http://127.0.0.1:9788',
9
+    baseURL: process.env.VUE_APP_BASE_API , //URL地址   环境变量文件
10
+    // baseURL: 'http://127.0.0.1:9788',
11
     timeout: 5000 ,//超时
11
     timeout: 5000 ,//超时
12
     withCredentials: true,  //跨域时若要发生cookie,需要设置该选项
12
     withCredentials: true,  //跨域时若要发生cookie,需要设置该选项
13
 })
13
 })
14
 console.log('service',process.env.VUE_APP_BASE_API);
14
 console.log('service',process.env.VUE_APP_BASE_API);
15
 // 请求拦截器
15
 // 请求拦截器
16
 service.interceptors.request.use(
16
 service.interceptors.request.use(
17
-  
17
+
18
     config => {
18
     config => {
19
       // sessionStorage.setItem('username',userInfo.account)
19
       // sessionStorage.setItem('username',userInfo.account)
20
       // sessionStorage.setItem('password',userInfo.password)
20
       // sessionStorage.setItem('password',userInfo.password)
21
       const username = window.sessionStorage.getItem('username')
21
       const username = window.sessionStorage.getItem('username')
22
       const password = window.sessionStorage.getItem('password')
22
       const password = window.sessionStorage.getItem('password')
23
       // console.log('sessionStorage.getItem',username,password,config.url);
23
       // console.log('sessionStorage.getItem',username,password,config.url);
24
-     
24
+
25
       if (config.method == 'post' ) {
25
       if (config.method == 'post' ) {
26
         config.data = {
26
         config.data = {
27
           ...config.data,
27
           ...config.data,
62
             //     type: 'error',
62
             //     type: 'error',
63
             //     duration: 5*1000
63
             //     duration: 5*1000
64
             // })
64
             // })
65
-        
65
+
66
 
66
 
67
             // 假设 10008 非法令牌  10012 其他客户端已经登陆
67
             // 假设 10008 非法令牌  10012 其他客户端已经登陆
68
             // if(res.code === 10008 || res.code === 10012){
68
             // if(res.code === 10008 || res.code === 10012){
99
     }
99
     }
100
 )
100
 )
101
 console.log('33333');
101
 console.log('33333');
102
-export default service;
102
+export default service;

+ 1 - 1
src/utils/request.js View File

18
 
18
 
19
 // create an axios instance
19
 // create an axios instance
20
 const service = axios.create({
20
 const service = axios.create({
21
-  baseURL: 'http://127.0.0.1:9788', // api的base_url
21
+  baseURL: process.env.VUE_APP_BASE_API, // api的base_url
22
   timeout: 3000000, // request timeout
22
   timeout: 3000000, // request timeout
23
   withCredentials: true
23
   withCredentials: true
24
 })
24
 })