浏览代码

no message

wangwei 4 年之前
父节点
当前提交
04a05ce1dd
共有 2 个文件被更改,包括 4 次插入17 次删除
  1. 2 1
      config/dev.env.js
  2. 2 16
      src/api/http.js

+ 2 - 1
config/dev.env.js

@@ -4,5 +4,6 @@ const prodEnv = require('./prod.env')
 
 module.exports = merge(prodEnv, {
   NODE_ENV: '"development"',
-  API_URL: '"http://192.168.100.8:3000"' // 后台地址
+  API_DEV_URL: '"http://192.168.100.8:3000"',// 后台地址
+  API_PRO_URL: '"http://127.0.0.1:3000"' // 本地测试后台地址
 })

+ 2 - 16
src/api/http.js

@@ -1,23 +1,15 @@
 // 导入axios
 import axios from 'axios';
-import cookie from 'js-cookie';
 import store from '@/store'
 import Vue from 'vue'
 
 
 // 进行一些全局配置
 // 公共路由(网络请求地址)
-// axios.defaults.baseURL = process.env.API_URL;
-// axios.defaults.baseURL = 'http://192.168.100.8:3000'; 
-axios.defaults.baseURL = 'http://127.0.0.1:3000/'; // 本地
+// axios.defaults.baseURL = process.env.API_DEV_URL; // 后台地址
+axios.defaults.baseURL = process.env.API_PRO_URL; // 本地后台地址
 // 请求响应超时时间
 axios.defaults.timeout = 5000;
-// 设置请求头
-// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
-
-// 设置请求超时
-axios.defaults.timeout = 5000 //设置超时时间为5s```
-
 // 设置post请求方式请求头
 // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
 // 请求拦截器
@@ -106,12 +98,10 @@ axios.interceptors.response.use(
 export default {
   get: function(path = '', data = {}) {
     return new Promise(function(resolve, reject) {
-      const token = cookie.get('token')
       axios.get(path, {
         params: data,
         headers:{
           'Content-Type': 'application/x-www-form-urlencoded',
-          'Authorization': token || ''
         }
       })
         .then(function(response) {
@@ -124,11 +114,9 @@ export default {
   },
   post: function(path = '', data = {}) {
     return new Promise(function(resolve, reject) {
-      const token = cookie.get('token')
       axios.post(path, data, {
         headers:{
           'Content-Type': 'application/json',
-          // 'Authorization': token || ''
         }
       })
         .then(function(response) {
@@ -150,12 +138,10 @@ export default {
         }
       })
         .then(function(response) {
-          console.log(`response`, response)
           console.log('========上传成功=====')
           resolve(response.data);
         })
         .catch(function(error) {
-          console.log(`error upload====`, error)
           reject(error);
         });
     });