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

shuyun-axios

v0.0.2

Published

在 Taro 中使用 axios。

Downloads

10

Readme

taro-axios

Taro 中使用 axios

源起

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

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

也就是说,taro-axios 只是 axiosTaro 重制版,并非是为 Taro 仿写了一个 axiosaxios 提供什么,taro-axios 也就提供什么。

特性

  • 使用 TypeScript 编写,类型友好
  • 基于 Taro 适配器,天然支持多端
  • 支持 API 一致的多端上传文件

安装

# yarn
yarn add taro-axios

# 或, npm
npm i taro-axios --save

使用

使用方法同 axios

只不过你得这样引入 axios

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 © FE