All Projects → fjc0k → Taro Axios

fjc0k / Taro Axios

Licence: mit
在 Taro 中使用 axios。

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Taro Axios

Vue H5 Pro
🚀 基于@vue/CLI3构建的移动端h5项目模板
Stars: ✭ 78 (-15.22%)
Mutual labels:  axios
Douban Movie Web
douban-movie-web
Stars: ✭ 85 (-7.61%)
Mutual labels:  axios
Vue Lottery
🎨 抽奖以及截屏保存图片至本地
Stars: ✭ 90 (-2.17%)
Mutual labels:  axios
Kikoeru Express
kikoeru 后端,不再维护,请到https://github.com/umonaca/kikoeru-express 获取更新
Stars: ✭ 79 (-14.13%)
Mutual labels:  axios
Community Modules
Stars: ✭ 1,258 (+1267.39%)
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
Axios Logger
Beautify Axios Logging Messages
Stars: ✭ 83 (-9.78%)
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
Poetryclub Backend
基于 laravel + vue.js 的诗词小筑网站后台页面与后端代码
Stars: ✭ 87 (-5.43%)
Mutual labels:  axios
Vue Study
vue-cli4 + vue2.6 + vuex + vue-router + axios + element-ui
Stars: ✭ 78 (-15.22%)
Mutual labels:  axios
Vue2 Qq
一个基于兴趣,为了学习,提高能力的项目
Stars: ✭ 90 (-2.17%)
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
Github User Search
Browse GitHub users with React
Stars: ✭ 87 (-5.43%)
Mutual labels:  axios

taro-axios NPM Version Build Status Coverage Status License

Taro 中使用 axios

源起

因为 Taro 不支持解析 package.json 里的 browser 属性,导致所有使用了该特性的包都可能无法在 Taro 里正常运行。不幸的是,axios 就是其中之一。

于是,taro-axios 预先解析了 axios 包中的 browser 属性并提供了 Taro 版的请求适配器后,将之打包出了一个 Taro 可用的版本。

也就是说,taro-axios 只是 axiosTaro 重制版,并非是为 Taro 仿写了一个 axiosaxios 提供什么,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)
  })

上传文件

为了支持多端上传文件,我们得引入 PostDataFileData 两个类,示例:

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].