{"id":13604062,"url":"https://github.com/fjc0k/taro-axios","last_synced_at":"2025-04-13T11:09:39.662Z","repository":{"id":38308069,"uuid":"186935234","full_name":"fjc0k/taro-axios","owner":"fjc0k","description":"在 Taro 中使用 axios。","archived":false,"fork":false,"pushed_at":"2022-12-09T15:03:28.000Z","size":359,"stargazers_count":138,"open_issues_count":7,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T11:09:35.249Z","etag":null,"topics":["axios","taro"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/taro-axios","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fjc0k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-16T02:22:39.000Z","updated_at":"2025-03-14T08:51:01.000Z","dependencies_parsed_at":"2023-01-25T14:30:39.114Z","dependency_job_id":null,"html_url":"https://github.com/fjc0k/taro-axios","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjc0k%2Ftaro-axios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjc0k%2Ftaro-axios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjc0k%2Ftaro-axios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjc0k%2Ftaro-axios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fjc0k","download_url":"https://codeload.github.com/fjc0k/taro-axios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248703199,"owners_count":21148118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","taro"],"created_at":"2024-08-01T19:00:39.186Z","updated_at":"2025-04-13T11:09:39.640Z","avatar_url":"https://github.com/fjc0k.png","language":"TypeScript","funding_links":[],"categories":["第三方库和组件"],"sub_categories":["Taro1"],"readme":"# taro-axios \u003ca href=\"https://www.npmjs.com/package/taro-axios\"\u003e\u003cimg src=\"https://badge.fury.io/js/taro-axios.svg\" alt=\"NPM Version\"\u003e\u003c/a\u003e \u003ca href=\"https://travis-ci.org/fjc0k/taro-axios\"\u003e\u003cimg src=\"https://travis-ci.org/fjc0k/taro-axios.svg?branch=master\" alt=\"Build Status\"\u003e\u003c/a\u003e \u003ca href=\"https://codecov.io/gh/fjc0k/taro-axios\"\u003e\u003cimg src=\"https://codecov.io/gh/fjc0k/taro-axios/branch/master/graph/badge.svg\" alt=\"Coverage Status\"\u003e\u003c/a\u003e \u003cimg src=\"https://badgen.net/github/license/fjc0k/taro-axios\" alt=\"License\"\u003e\n\n在 [Taro](https://github.com/NervJS/taro) 中使用 [axios](https://github.com/axios/axios)。\n\n## 源起\n\n因为 `Taro` 不支持解析 `package.json` 里的 `browser` 属性，导致所有使用了该特性的包都可能无法在 `Taro` 里正常运行。不幸的是，`axios` 就是其中之一。\n\n于是，`taro-axios` 预先解析了 `axios` 包中的 `browser` 属性并提供了 `Taro` 版的请求适配器后，将之打包出了一个 `Taro` 可用的版本。\n\n也就是说，`taro-axios` 只是 `axios` 的 `Taro` 重制版，并非是为 `Taro` 仿写了一个 `axios`。`axios` 提供什么，`taro-axios` 也就提供什么。\n\n## 特性\n\n- 使用 TypeScript 编写，类型友好\n- 基于 Taro 适配器，天然支持多端\n- 支持 API 一致的多端上传文件\n\n## 安装\n\n### Taro 3\n\n```bash\n# yarn\nyarn add taro-axios\n\n# 或, npm\nnpm i taro-axios --save\n```\n\n### Taro 1、Taro 2\n\n\n```bash\n# yarn\nyarn add taro-axios@0.7.0\n\n# 或, npm\nnpm i taro-axios@0.7.0 --save\n```\n\n## 使用\n\n使用方法同 [axios](https://github.com/axios/axios#axios)。\n\n只不过你得这样引入 `axios`：\n\n```ts\nimport { axios } from 'taro-axios'\n// 自版本 0.7.0 起你也可以这样引入:\n// import axios from 'taro-axios'\n\naxios\n  .get('https://jsonplaceholder.typicode.com/todos/1')\n  .then(res =\u003e {\n    console.log(res.data)\n  })\n```\n\n## 上传文件\n\n为了支持多端上传文件，我们得引入 `PostData` 和 `FileData` 两个类，示例：\n\n```ts\nimport { axios, PostData, FileData } from 'taro-axios'\n\nasync function uploadImage() {\n  const { tempFilePaths } = await Taro.chooseImage({ count: 1 })\n  Taro.showLoading({ title: '图片上传中...' })\n  const res = await axios.post(\n    'https://sm.ms/api/upload',\n    new PostData({\n      smfile: new FileData(tempFilePaths[0]),\n      ssl: true,\n      format: 'json',\n    }),\n  )\n  Taro.hideLoading()\n  Taro.showModal({\n    title: '返回结果',\n    content: JSON.stringify(res.data),\n  })\n}\n```\n\n## 许可\n\nMIT © Jay Fong\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjc0k%2Ftaro-axios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffjc0k%2Ftaro-axios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjc0k%2Ftaro-axios/lists"}