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

@aocoding/mini-axios

v0.1.4

Published

> 小程序 request 增强库,api 参考 axios,提供完整的 ts 支持

Downloads

30

Readme

miniAxios

小程序 request 增强库,api 参考 axios,提供完整的 ts 支持

支持平台

引入:

  1. npm i @aocoding/mini-axios
  2. import miniAxios from '@aocoding/mini-axios';

使用:

// http.js
import miniAxios from './libs/wxAxios.min.js'
miniAxios.get(url).then(res => {
    console.log(res )
})
// 或者
miniAxios.defaults.baseURL = 'https://xxx.com/'   // 配置默认地址
miniAxios.get(url).then(res => {
    console.log(res)
})

请求配置:

部分参数请参考小程序本身配置,如默认配置不能满足要求,可以直接传入配置。(对修改开放)

| 参数 | 说明 | 类型 | 默认值 | | ----------------- | -------------------- | -------- | ------------------------------------------------------------ | | method | 请求方法 | string | GET | | baseURL | 默认请求基础地址 | | '' | | timeout | 超时时间 | number | 3000 | | headers | 请求发送时候的请求头 | object | {'Content-Type': 'application/json'} | | dataType | 返回时的数据类型 | string | JSON | | transformRequest | 请求数据转换 | array | [ function(data: any, headers: any): any { return data } ] | | transformResponse | 返回数据转换 | array | [ function(data: any): any { return data } ] | | validateStatus | 返回数据状态验证 | function | validateStatus(status: number): boolean { return status >= 200 && status < 300 } |

拦截器

request

// 1.第一个 request 的拦截器
miniAxios.interceptors.request.use(config => {
    config.data.companyId = 1
    // ...do something
    return config
})
// 2.第二个 request 的拦截器,
miniAxios.interceptors.request.use(config => {
    config.data.token = wx.getStorageSync('token')
    // ...do something
    return config
})

response

// 1.第一个 response 的拦截器
axios.interceptors.response.use(response => {
   if (response.statusCode === 200) {
      // ...do something
   }
   console.log(response.header);
    return response
})
// 2.第二个 response 的拦截器,
axios.interceptors.response.use(function (response) {
    if (response.status === 400) {
      // ...do something
   }
    return response
})

Bug,反馈

请在Issues中发帖

License


MIT