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

axios-taro4-adapter

v0.0.2

Published

axios adaptor for taro.request

Downloads

27

Readme

axios-taro4-adapter

npm NPM

适配taro4.0.4

基于 axios支持自定义适配器,只需要针对不同环境下的http请求api进行适配进行替换,axios可以使用在任意平台。

由于 axios在其他项目中大量使用,本项目实现 Taro框架下的适配器,可以在 Taroa项目中完美使用原汁原味的 axios,统一团队前端技术栈,统一http请求类库。

采用此方式对项目零侵入,开发者专注于 axios的api即可。

有用点小星星支持~

Quick start

  1. npm i [email protected]
  2. npm i axios-taro4-adapter
  3. create axios instance

仅需2行代码,完美使用 axios替换 Taro.request

// api.js
import axios from "axios";
import { TaroAdapter } from "axios-taro-adapter";

const API_URL = "https://api.xxxx.com/";
const instance = axios.create({
  baseURL: API_URL,
  timeout: 10000,
  adapter: TaroAdapter, // add this line,添加这一行使用taroAdapter
});

export const postData = data => {
    return instance.post("/api/test", data);
}

例如: 原汁原味的拦截器

// interceptors for request
instance.interceptors.request.use(
  function (config) {
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

// interceptors for response
instance.interceptors.response.use(
  function (response) {
    if (response.data.code !== 0) {
      return Promise.reject(response.data);
    } else {
      return response.data;
    }
  },
  function (error) {
    return Promise.reject(error.message);
  }
);