
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
axios-taro4-adapter
Advanced tools
适配taro4.0.4
基于 axios
支持自定义适配器,只需要针对不同环境下的http请求api进行适配进行替换,axios
可以使用在任意平台。
由于 axios
在其他项目中大量使用,本项目实现 Taro
框架下的适配器,可以在 Taroa
项目中完美使用原汁原味的 axios
,统一团队前端技术栈,统一http请求类库。
采用此方式对项目零侵入,开发者专注于 axios
的api即可。
有用点小星星支持~
npm i axios@0.27.2
npm i axios-taro-adapter
仅需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);
}
);
FAQs
axios adaptor for taro.request
We found that axios-taro4-adapter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.