1.5.2 • Published 7 months ago

@uni-helper/axios-adapter v1.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@uni-helper/axios-adapter

适用于 Vue2 和 Vue3 的 uniapp Axios 适配器

安装

pnpm i @uni-helper/axios-adapter axios

使用

Vue2Vue3
App快应用微信小程序支付宝小程序百度小程序字节小程序QQ 小程序
HBuilderX 3.4.8app-vueapp-nvue
钉钉小程序快手小程序飞书小程序京东小程序
H5-SafariAndroid Browser微信浏览器(Android)QQ 浏览器(Android)ChromeIEEdgeFirefoxPC-Safari

基本用法

import axios from "axios";
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";

axios.defaults.adapter = createUniAppAxiosAdapter();

或者创建自定义实例

import axios from "axios";
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";

const instance = axios.create({ adapter: createUniAppAxiosAdapter() });

useAxios 一起使用

import axios from "axios";
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";

axios.defaults.adapter = createUniAppAxiosAdapter();
const { data, isFinished } = useAxios("/posts");

上传和下载

// 下载
axios.download("/");
// or
axios.request({
  url: "/",
  method: "download",
});

// 上传
axios.upload("/", new File([new Blob()], "fake file"));
// or
axios.request({
  url: "/",
  method: "upload",
  data: new File([new Blob()], "fake file"),
});

小程序

自 axios 1.4.0 开始,axios 内部已经处理了小程序的兼容性问题

小程序没有 FormDataBlob 对象, 使用 pnpm add miniprogram-formdata miniprogram-blob 来安装对应的 polyfill,然后使用插件

// vite.config.js
import uniAxiosAdapter from "@uni-helper/axios-adapter/vite";

export default {
  plugins: [
  ...
  uniAxiosAdapter()
  ...
  ],
}

如果你使用的是 Vue CLI,改用 @uni-helper/axios-adapter/webpack 即可

版本

自 1.4.0 开始,请始终保持主版本号和次版本号与 axios 一致。例如当你安装了 1.5.1 版本时,你可以安装 axios 的 1.5.x 版本。

这样做的目的是始终支持最新的 axios。

1.5.2

7 months ago

1.5.1

8 months ago

1.5.0

8 months ago

1.4.0

12 months ago

0.0.3

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.2

1 year ago

0.0.1

2 years ago