umi-request cancel lib, you can easy cancel your request.
Chinese documents|English documents
yarn add easy-axios-cancel
npm install --save easy-axios-cancel
Parameter | Description | Type | Optional Value | Default Value |
---|---|---|---|---|
cancelKey | cancel request unique ID, top level | String | ||
urlUnique | cancel request compare with URL | String | Regexp | 'host'、'path'、'search'、RegExp | |
urlBase | URL constructor params | DOMString | window.location.origin | |
urlUniqueList | list to match, it can be use with urlUnique to match url | Array | ||
cancelHandleType | break by abortController or cancelToken |
String | 'cancelToken'、'abortController' | 'cancelToken' |
-
-- host [string]
compare with host, If it is the same, cancel the previous request.
-
-- path [string]
compare with host and pathname, If it is the same, cancel the previous request.
-
-- search [string]
compare with host and pathname and search, If it is the same, cancel the previous request.
-
-- RegExp [RegExp]
compare href address with
regexp
, If it is test true, cancel the previous request.
import registryCancelMiddleware from "easy-axios-cancel";
import axios from "axios";
const req = axios.create({
cancelHandleType: "abortController", // 默认使用'cancelToken',可以选择使用abortController
});
// 注册取消扩展
registryCancelMiddleware(req);
/* cancelKey */
request.get("/api/v1/xxx?id=1", {
cancelKey: "cancelKey1", // 第一优先级
});
axios