umi-request cancel lib, you can easy cancel your request.
Chinese documents|English documents
yarn add umi-request-cancel
npm install --save umi-request-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 |
-
-- 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 request, { extend } from "umi-request-cancel";
const req = extend({
timeout: 3000,
urlBase: process.env.NODE_ENV === 'development' ? 'http://localhost': ''
urlUnique: 'search'
})
/* cancelKey */
request
.get("/api/v1/xxx?id=1", {
cancelKey: "cancelKey1", // 第一优先级
})
umi-request