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 🙏

© 2026 – Pkg Stats / Ryan Hefner

axios-add-loading

v0.0.1

Published

本库通过`axios`的[interceptors](https://github.com/axios/axios#interceptors)帮助你设置ajax请求中的loading

Downloads

16

Readme

axios-add-loading

本库通过axiosinterceptors帮助你设置ajax请求中的loading

安装

npm i -S axios-add-loading

语法

createAddLoadingInterceptor(
  axios: AxiosInstance,
  options: AxiosAddLoadingOptions
)

参数

如何使用

import createAddLoadingInterceptor from 'axios-add-loading'
import axios from 'axios'
const instance = axios.create()
const options = {
  showLoading: true,
  delEmpty: true,
  openLoading: () => { /* 打开loading方法 */},
  closeLoading: () => { /* 关闭loading方法 */},
  isResOk: res => { /* 对json进行过滤,返回boolean,满足条件的将会返回,参数为AxiosResponse.data */ },
  onResNotOk: res => { /* 只有设置了isResOk才会生效,对不满足isResOk的请求,将会触发onResNotOk的回掉, 参数为 AxiosResponse.data*/ },
  onResError: e => { /* ajax请求错误触发,如404,500等 */}
}
createAddLoadingInterceptor(instance, options)

instance({
  method: 'get',
  url: 'dir/xxx',
  params: { foo: 'bar' },
  // 这里可覆盖showLoading配置
  showLoading: false,
  // 这里可覆盖delEmpty配置
  delEmpty: false,
})

参数说明

delEmpty: boolean

是否删除 get 请求中 params 中为空的字段 xxx/dir?a=&b=3 => xxx/dir?b=3

delEmpty: true

showLoading: boolean

是否显示loading,需结合openLoadingcloseLoading使用

showLoading: true

openLoading: () => void

显示 loading 的方法, 拦截器发起请求前触发

openLoading: () => { /* 打开loading方法 */}

closeLoading: () => void

隐藏 loading 的方法, 拦截器完成请求触发

closeLoading: () => { /* 关闭loading方法 */}

isResOk: res => boolean

大多数情况下response-schema只需要用到data,本方法主要过滤response-schema参数res为其中的data,定义规则确定那些返回内容是符合规则的,如果未设置,拦截器将会返回response-schema

isResOk: res => res.code === 200

onResNotOk: res => void

只有设置了 isResOk 才会生效,对不符合isResOk的请求进行处理

onResNotOk: res => {
  if (res.code === 401) {
    gotoLogin()
  }
}

onResError: e => void

e为handling-errors, 对于请求异常的错误处理

onResError: e => {
  if (e.response.status === 401) {
    gotoLogin()
  }
}