Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axios-taro4-adapter

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-taro4-adapter

axios adaptor for taro.request

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

axios-taro4-adapter

npm NPM

适配taro4.0.4

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

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

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

有用点小星星支持~

Quick start

  1. npm i axios@0.27.2
  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);
  }
);

Keywords

FAQs

Package last updated on 22 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc