Commit 43413329ccae2d714f570c1b6b8cf98568dbd478

Authored by sqy
1 parent 1ff6ddf0

fix:细微调整defHttp请求

1 1 /**
2 2 * custom http request
3 3 */
4   -function DefHttp() {
  4 +function createAxios(options) {
5 5 /**
6 6 * 创建实例
7 7 */
8 8 const instance = axios.create({
9   - baseURL: DefHttp.baseURL,
10   - timeout: DefHttp.timeout,
  9 + baseURL: options.baseURL,
  10 + timeout: options.timeout,
11 11 headers: {
12 12 "content-type": "application/json; charset=UTF-8",
13   - "X-Authorization": "Bearer " + DefHttp.token,
  13 + "X-Authorization": "Bearer " + options.token,
14 14 },
15 15 });
16 16 /**
... ... @@ -18,17 +18,14 @@ function DefHttp() {
18 18 */
19 19 instance.interceptors.response.use(
20 20 function (response) {
21   - return response;
  21 + return response.data;
22 22 },
23 23 function (error) {
24 24 if (error.response.status == 401) {
25   - alert(error.response.data.message);
  25 + layer.alert('登录超时,请重新登录');
26 26 }
27 27 return Promise.reject(error);
28 28 }
29 29 );
30 30 return instance;
31 31 }
32   -DefHttp.timeout = 10 * 1000;
33   -DefHttp.token = "";
34   -DefHttp.baseURL = "/api/";
... ...