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

zhlt-axios

v0.0.2

Published

An ajax dir based on axios for @zhuifintech

Downloads

1

Readme

zhlt-axios

一个基于axios和业务的ajax请求封装,不限项目使用的框架,只需全局安装即可使用。

使用

  npm i zhlt-axios -g

or

  yarn global add zhlt-axios

then

  zhlt-axios

选项

-o, --output: 最终的文件的输出路径。默认是当前路径,如果指定的路径下有名为ajax的目录,则不会覆盖。

输出的目录结构

└── ajax
   ├── index.js
   └── interceptors
       ├── index.js
       ├── request
       │   └── index.js
       └── response
           └── index.js
  • ajax/index.js对外导出一个被初始化的axios对象,文件中有一些初始的配置,生成目录之后使用者可以任意更改

  • interceptors目录下是axios的拦截器,包括请求拦截和响应拦截,具体参考链接。

  • interceptors/requestinterceptors/response目录下各有一个index.js文件,使用者在添加了拦截器之后,应该也在对应的index.js内引入,因为在ajax/interceptors/index.js中会对所有的拦截器做处理。根据(培伟大佬翻查)源码会发现,request拦截器越添加的越执行,response拦截器越添加的越执行,因此在interceptors/requestinterceptors/response下的index.js中添加拦截器时应需注意执行的时机。

  • 本插件的使用者在添加拦截器时,应遵循如下格式,例如,添加一个请求拦截:

      import store from './../../../store'
    
      export default {
        onFulfilled: config => {
          config.data.deviceType = 3
    
          // 处理某些不是在当前项目下的接口
          if (!config.url.match(/^\/letou/)) {
            config.url = `/letou/bi${config.url}`
          }
    
          config.headers['sessionKey'] = store.getters['getSessionKey']
    
          return config
        },
        onRejected: reject => {
          return reject
        }
      }

    即,对外导出的是一个对象,包括两个字段onFulfilledonRejected。两者均是函数,且前者接受一个config参数,内容为请求的配置;后者接受一个reject参数,内容为请求的拒绝信息。在响应拦截中应使用同样的格式对外导出对象。

欢迎各位小伙伴一起贡献代码