npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dpdfe/axios

v1.0.3

Published

- 支持配置策略同一个请求,最多发送一次,如果发送多次,自动取消上次请求 - 支持配置策略同一个请求,最多发送一次,触发多次,不发送本次请求 - 提供取消页面所有请求的方法

Downloads

1

Readme

Features

  • 支持配置策略同一个请求,最多发送一次,如果发送多次,自动取消上次请求
  • 支持配置策略同一个请求,最多发送一次,触发多次,不发送本次请求
  • 提供取消页面所有请求的方法

安装

  • 使用 npm:
npm i --save @dpdfe/axios
  • 引入
import axios from '@dpdfe/axios'

使用方法

基于 axios 进行封装,可以像使用 axios 一样使用@dpdfe/axios

  • 支持配置策略同一个请求,最多发送一次,如果发送多次,自动取消上次请求
  • 配置全局 axios 策略
 const instance = axios.create({
        baseURL: 'http://localhost:3000/',
        timeout: 1000000,
        strategy: AjaxStrategy.CANCEL_LAST_AT_MOST_ONCE, // 多个重复请求发送,自动取消先发送的请求
 });
  • 针对单个请求配置 axios 策略
instance.get('/', {strategy: AjaxStrategy.CANCEL_LAST_AT_MOST_ONCE})
  • 支持配置策略同一个请求,最多发送一次,触发多次,不发送本次请求
  • 配置全局 axios 策略
 const instance = axios.create({
        baseURL: 'http://localhost:3000/',
        timeout: 1000000,
        strategy: AjaxStrategy.CANCEL_CURRENT_AT_MOST_ONCE, // 多个重复请求发送,仅发送第一个请求,后面重复的被拦截不发送
 });
  • 针对单个请求配置 axios 策略
instance.get('/', {strategy: AjaxStrategy.CANCEL_CURRENT_AT_MOST_ONCE})
  • 路由变化时,可以取消上一个页面的请求,react 中使用方法
 <Route
    path={route.path}
    render={(props) => {
       instance.cancelReqs('get');
       return <route.component {...props} routes={route.routes} />;
    }}
/>

注意事项

由于重复请求或调用 cancelReqs 方法而取消的请求,会抛出异常,可以根据实际场景进行处理,axios.isCancel 方法来判断是由手动取消引发的异常。如:

   instance?.interceptors.response.use(
            function (response) {
                return response;
            },
            function (error) {
                if (axios.isCancel(error)) {
                     // 手动取消引发的异常,进行处理
                    return new AjaxCancelError('手动取消了请求');
                }
                return Promise.reject(error);
            },
        );