12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import axios from "axios";
- // import { gettoken } from "../services/token";
- // axios.defaults.withCredentials=true;
- const instance = axios.create({
- //baseURL: 'http://192.168.2.164:8899', //请求的基础地址
- baseURL: 'https://scrm.zzliaoyuan.com/backend', //请求的基础地址
- timeout: 60000, //请求超时的时间
- });
- //发一个get请求
- export const get = (url, params) => instance.get(url, { params });
- //发一个post请求
- export const post = (url, data) => instance.post(url, data);
- export const put = (url, params) => instance.put(url, params);
- export default instance;
- // Add a request interceptor
- //全局请求拦截,发起网络请求之前执行
- instance.interceptors.request.use(
- function (config) {
- // Do something before request is sent
- // config.headers.Authorization = gettoken();
- return config;
- },
- function (error) {
- // Do something with request error
- return Promise.reject(error);
- }
- );
- // Add a response interceptor
- //全局响应拦截,网络请求返回之后执行
- instance.interceptors.response.use(
- function (response) {
- // Any status code that lie within the range of 2xx cause this function to trigger
- // Do something with response data
- return response.data;
- },
- function (error) {
- // Any status codes that falls outside the range of 2xx cause this function to trigger
- // Do something with response error
- return Promise.reject(error);
- }
- );
|