Bläddra i källkod

添加axios-retry

Michael Wang 4 år sedan
förälder
incheckning
abe0f57054
6 ändrade filer med 20 tillägg och 3 borttagningar
  1. 1 0
      package.json
  2. 1 1
      src/api/login.js
  3. 2 0
      src/plugins/axiosApp.js
  4. 2 2
      src/plugins/axiosIndex.js
  5. 2 0
      src/plugins/axiosNoAuth.js
  6. 12 0
      yarn.lock

+ 1 - 0
package.json

@@ -18,6 +18,7 @@
   "dependencies": {
     "axios": "^0.19.2",
     "axios-progress-bar": "^1.2.0",
+    "axios-retry": "^3.1.8",
     "bootstrap": "^4.5.0",
     "core-js": "^3.6.5",
     "element-ui": "^2.13.2",

+ 1 - 1
src/api/login.js

@@ -1,4 +1,4 @@
-import { httpApp } from "@/plugins/axiosApp";
+import { httpApp } from "@/plugins/axiosIndex";
 
 export function loginByUsername({
   accountType,

+ 2 - 0
src/plugins/axiosApp.js

@@ -5,6 +5,7 @@ import { loadProgressBar } from "axios-progress-bar";
 import cachingGet from "./axiosCache";
 import { notifyInvalidTokenThrottled } from "./axiosNotice";
 import { getToken, removeToken } from "../auth/auth";
+import axiosRetry from "axios-retry";
 
 const PLATFORM = "Wap";
 
@@ -20,6 +21,7 @@ const config = {
 const cacheGetUrls = [];
 
 const _axiosApp = axios.create(config);
+axiosRetry(_axiosApp);
 
 function gToken(uri, token) {
   const now = Date.now();

+ 2 - 2
src/plugins/axiosIndex.js

@@ -1,2 +1,2 @@
-import "./axiosApp";
-import "./axiosNoAuth";
+export { default as httpApp } from "./axiosApp";
+export { default as httpNoAuth } from "./axiosNoAuth";

+ 2 - 0
src/plugins/axiosNoAuth.js

@@ -2,6 +2,7 @@ import Vue from "vue";
 import axios from "axios";
 import { loadProgressBar } from "axios-progress-bar";
 import cachingGet from "./axiosCache";
+import axiosRetry from "axios-retry";
 
 const config = {
   timeout: 60 * 1000, // Timeout
@@ -9,6 +10,7 @@ const config = {
 const cacheGetUrls = [];
 
 const _axiosNoAuth = axios.create(config);
+axiosRetry(_axiosNoAuth);
 
 /**
  * 本应用的无auth api,或者第三方的api

+ 12 - 0
yarn.lock

@@ -2470,6 +2470,13 @@ axios-progress-bar@^1.2.0:
   resolved "https://registry.yarnpkg.com/axios-progress-bar/-/axios-progress-bar-1.2.0.tgz#f9ee88dc9af977246be1ef07eedfa4c990c639c5"
   integrity sha512-PEgWb/b2SMyHnKJ/cxA46OdCuNeVlo8eqL0HxXPtz+6G/Jtpyo49icPbW+jpO1wUeDEjbqpseMoCyWxESxf5pA==
 
+axios-retry@^3.1.8:
+  version "3.1.8"
+  resolved "https://registry.npm.taobao.org/axios-retry/download/axios-retry-3.1.8.tgz#ffcfed757e1fab8cbf832f8505bb0e0af47c520c"
+  integrity sha1-/8/tdX4fq4y/gy+FBbsOCvR8Ugw=
+  dependencies:
+    is-retry-allowed "^1.1.0"
+
 axios@^0.19.2:
   version "0.19.2"
   resolved "https://registry.npm.taobao.org/axios/download/axios-0.19.2.tgz?cache=0&sync_timestamp=1594827569427&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faxios%2Fdownload%2Faxios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
@@ -6221,6 +6228,11 @@ is-resolvable@^1.0.0:
   resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88"
   integrity sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==
 
+is-retry-allowed@^1.1.0:
+  version "1.2.0"
+  resolved "https://registry.npm.taobao.org/is-retry-allowed/download/is-retry-allowed-1.2.0.tgz#d778488bd0a4666a3be8a1482b9f2baafedea8b4"
+  integrity sha1-13hIi9CkZmo76KFIK58rqv7eqLQ=
+
 is-stream@^1.1.0:
   version "1.1.0"
   resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"