1.1.1 • Published 2 years ago

easy-umi-request-cancel v1.1.1

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

easy-umi-request-cancel

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

中文文档|英文文档

NPM version

安装

yarn add easy-umi-request-cancel
npm install --save easy-umi-request-cancel

扩展属性

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

参数详情

urlUnique

  • -- host string

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

  • -- path string

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

  • -- search string

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

  • -- RegExp RegExp

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

案例

import cancelMiddleware from "easy-umi-request-cancel";
import request, { extend } from 'umi-request'

request.use(
  cancelMiddleware,
  { core: true }
)

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

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago