fjc0k / Taro Axios
Licence: mit
在 Taro 中使用 axios。
Stars: ✭ 92
Programming Languages
typescript
32286 projects
Labels
Projects that are alternatives of or similar to Taro Axios
Kikoeru Express
kikoeru 后端,不再维护,请到https://github.com/umonaca/kikoeru-express 获取更新
Stars: ✭ 79 (-14.13%)
Mutual labels: axios
Retrofit Cjs
retrofit-cjs 是一个基于JavaScript装饰器(Decorator)和 axios 实现的网络请求库, 支持Vue / React / react-native 等常用框架
Stars: ✭ 87 (-5.43%)
Mutual labels: axios
Vue Cli3 Multipage
由vue-cli3搭建的多页面多路由初始化项目包,包含ESlint,Axios,vue-router,vuex,babel,以及自己封装的异步请求API接口。
Stars: ✭ 76 (-17.39%)
Mutual labels: axios
Spala
Spala (SPA LARAVEL): a modern lightweight CMS for Laravel and Vue developers (open source project).
Stars: ✭ 91 (-1.09%)
Mutual labels: axios
React Ufo
🛸 react-ufo - A simple React hook to help you with data fetching 🛸
Stars: ✭ 85 (-7.61%)
Mutual labels: axios
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-4.35%)
Mutual labels: axios
Bottle Vue Kickstart
🍕 Very basic Bottle kickstart kit with Vue.js and Webpack. Included Axios, Autoprefixer, Babel, Webpack config, demo app with Bulma and Web font loader.
Stars: ✭ 83 (-9.78%)
Mutual labels: axios
Vue Study
vue-cli4 + vue2.6 + vuex + vue-router + axios + element-ui
Stars: ✭ 78 (-15.22%)
Mutual labels: axios
Vue2 Multi Uploader
Drag and drop multiple file uploader with Vue.js v2 and Axios
Stars: ✭ 77 (-16.3%)
Mutual labels: axios
Vue H5 Template
🎉vue搭建移动端开发,基于vue-cli4.0+webpack 4+vant ui + sass+ rem适配方案+axios封装,构建手机端模板脚手架
Stars: ✭ 1,261 (+1270.65%)
Mutual labels: axios
Reactjs Spring Boot Crud Full Stack App
Learn how to develop a full-stack CRUD application using React as frontend and spring boot as backend.
Stars: ✭ 90 (-2.17%)
Mutual labels: axios
Egg Vue Webpack Boilerplate
Egg Vue Server Side Render (SSR) / Client Side Render (CSR)
Stars: ✭ 1,302 (+1315.22%)
Mutual labels: axios
taro-axios
源起
因为 Taro
不支持解析 package.json
里的 browser
属性,导致所有使用了该特性的包都可能无法在 Taro
里正常运行。不幸的是,axios
就是其中之一。
于是,taro-axios
预先解析了 axios
包中的 browser
属性并提供了 Taro
版的请求适配器后,将之打包出了一个 Taro
可用的版本。
也就是说,taro-axios
只是 axios
的 Taro
重制版,并非是为 Taro
仿写了一个 axios
。axios
提供什么,taro-axios
也就提供什么。
特性
- 使用 TypeScript 编写,类型友好
- 基于 Taro 适配器,天然支持多端
- 支持 API 一致的多端上传文件
安装
Taro 3
# yarn
yarn add taro-axios
# 或, npm
npm i taro-axios --save
Taro 1、Taro 2
# yarn
yarn add [email protected]
# 或, npm
npm i [email protected] --save
使用
使用方法同 axios。
只不过你得这样引入 axios
:
import { axios } from 'taro-axios'
// 自版本 0.7.0 起你也可以这样引入:
// import axios from 'taro-axios'
axios
.get('https://jsonplaceholder.typicode.com/todos/1')
.then(res => {
console.log(res.data)
})
上传文件
为了支持多端上传文件,我们得引入 PostData
和 FileData
两个类,示例:
import { axios, PostData, FileData } from 'taro-axios'
async function uploadImage() {
const { tempFilePaths } = await Taro.chooseImage({ count: 1 })
Taro.showLoading({ title: '图片上传中...' })
const res = await axios.post(
'https://sm.ms/api/upload',
new PostData({
smfile: new FileData(tempFilePaths[0]),
ssl: true,
format: 'json',
}),
)
Taro.hideLoading()
Taro.showModal({
title: '返回结果',
content: JSON.stringify(res.data),
})
}
许可
MIT © Jay Fong
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].