0.9.1 • Published 2 years ago

easy-axios-cancel v0.9.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

easy-axios-cancel

umi-request 取消请求第三方库, 你可以很方便的中断 umi-request 请求

中文文档|英文文档

NPM version

安装

yarn add easy-axios-cancel
npm install --save easy-axios-cancel

扩展属性

属性描述类型可选值默认值
cancelKey中断请求唯一 ID, 最高优先级String
urlUnique使用 URL 进行比较String | Regexp'host'、'path'、'search'、RegExp
urlBaseURL 构造函数的第二个参数DOMStringwindow.location.origin
urlUniqueList匹配地址集合,可以和urlUnique共同使用Array
cancelHandleType设置使用abortController或者cancelToken中断请求String'cancelToken'、'abortController''cancelToken'

参数详情

urlUnique

  • -- host string

    使用请求地址的 host 进行比较,如果两个请求匹配内容相同,则会中断上一个请求

  • -- path string

    使用请求地址的 host 与 pathname 进行比较,如果两个请求匹配内容相同,则会中断上一个请求

  • -- search string

    使用请求地址的 host 与 pathname 与 search 进行比较,如果两个请求匹配内容相同,则会中断上一个请求

  • -- RegExp RegExp

    使用正则表达式对两个请求的 href 进行比较,如果两个请求匹配内容相同,则会中断上一个请求

案例

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

0.9.1

2 years ago

0.9.0

2 years ago