index.js 1.67 KB
import axios from "axios";
import {url,error,success} from "./config";
let config = {
    // baseURL:process.env.VUE_APP_baseURL,// || process.env.apiUrl || ""
    // timeout: 60 * 1000, // Timeout
    // withCredentials: true, // Check cross-site Access-Control
    headers: {
    
    }
  };
  
  const _axios = axios.create(config);
  
  _axios.interceptors.request.use(
    function (config) {
      // debugger
      // Do something before request is sent
      return config;
    },
    function (error) {
      // Do something with request error
      return Promise.reject(error);
    }
  );
  
  // Add a response interceptor
  _axios.interceptors.response.use(
    function (response) {
      // debugger;
      // Do something with response data
      if ("data" in response) {
        
        // debugger;
        return config.success(response.data)
      }
      // debugger;
      console.log("非标准输出!")
      
      return response;
    },
    function (error) {
      // Do something with response error
      return Promise.reject(error);
    }
  );
  

  export default {
      GET(target,params={}){
        return _axios.get((target),{params})
                    
      },
      POST(target,params={}){
        return _axios.post((target),params)
      }
  }
//   Plugin.install = function (Vue, options) {
//     Vue.axios = _axios;
//     window.axios = _axios;
//     Object.defineProperties(Vue.prototype, {
//       axios: {
//         get() {
//           return _axios;
//         }
//       },
//       $axios: {
//         get() {
//           return _axios;
//         }
//       },
  
//     });
//   };
  
//   Vue.use(Plugin)
  
//   export default Plugin;