request.js 1.02 KB
Newer Older
leiqingsong's avatar
leiqingsong committed
1 2 3 4 5 6
import axios from "axios";
import { Toast } from "vant";

let loading = null;

const service = axios.create({
7
  baseURL: "http://192.168.204.152:8997",
leiqingsong's avatar
leiqingsong committed
8
  timeout: 5000
9
});
leiqingsong's avatar
leiqingsong committed
10 11 12

service.interceptors.request.use(
  config => {
13 14
    config.headers["Authorization"] =
      "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJpZFwiOjEsXCJpbnZpdGVDb2RlXCI6XCIxXCIsXCJwYXNzd29yZFwiOlwiMTIzXCIsXCJ1c2VySWRcIjpcIjFcIixcInVzZXJMZXZlbFwiOjR9IiwiaWF0IjoxNjE0MzI3OTY0fQ.f9RPBOMo0BMMbWPnQIhvfLe535as60dk_SZoXMYOT3bHYjoYST-mivTcKC-u4grEpYZMax9RgyuHXCYydZPzQw";
15
    if (!config.loading) {
leiqingsong's avatar
leiqingsong committed
16 17 18 19 20 21 22 23 24
      loading = Toast.loading({
        forbidClick: true,
        message: "加载中..."
      });
    }
    return config;
  },
  error => {
    if (loading) Toast.clear();
25
    console.log("rqquest====错误", error);
leiqingsong's avatar
leiqingsong committed
26
  }
27
);
leiqingsong's avatar
leiqingsong committed
28 29 30 31 32 33 34 35

service.interceptors.response.use(
  response => {
    if (loading) Toast.clear();
    const res = response.data;
    return res;
  },
  error => {
36 37
    if (loading) Toast.clear();
    console.log("response===错误", error);
leiqingsong's avatar
leiqingsong committed
38
  }
39
);
leiqingsong's avatar
leiqingsong committed
40 41

export default service;