Skip to content

itkui/easy-umi-request-cancel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
urlBase URL 构造函数的第二个参数 DOMString window.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