@uni-helper/axios-adapter 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,59 +12,73 @@ pnpm i @uni-helper/axios-adapter axios
12
12
 
13
13
  ## 使用
14
14
 
15
+ <details>
16
+ <summary>点击查看平台兼容性</summary>
17
+
18
+ | Vue2 | Vue3 |
19
+ | ---- | ---- |
20
+ | √ | √ |
21
+
22
+ | App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ 小程序 |
23
+ | ---------------------------------------- | ------ | ---------- | ------------ | ---------- | ---------- | --------- |
24
+ | HBuilderX 3.4.8<br/>app-vue<br/>app-nvue | √ | √ | √ | √ | √ | √ |
25
+
26
+ | 钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 |
27
+ | ---------- | ---------- | ---------- | ---------- |
28
+ | √ | √ | √ | √ |
29
+
30
+ | H5-Safari | Android Browser | 微信浏览器(Android) | QQ 浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
31
+ | --------- | --------------- | ------------------- | ------------------ | ------ | --- | ---- | ------- | --------- |
32
+ | √ | √ | √ | √ | √ | √ | √ | √ | √ |
33
+
34
+ </details>
35
+
15
36
  ### 基本用法
16
37
 
17
38
  ```ts
18
39
  import axios from "axios";
19
40
  import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
20
41
 
21
- const instance = axios.create({
22
- adapter: createUniAppAxiosAdapter(),
23
- });
42
+ axios.defaults.adapter = createUniAppAxiosAdapter();
24
43
  ```
25
44
 
26
- ### 与 useAxios 一起使用
45
+ 或者创建自定义实例
27
46
 
28
47
  ```ts
29
48
  import axios from "axios";
30
- import { useAxios } from "@vueuse/integrations/useAxios";
31
49
  import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
32
50
 
33
- const instance = axios.create({
34
- adapter: createUniAppAxiosAdapter(),
35
- });
36
-
37
- const { data, isFinished } = useAxios("/posts", instance);
51
+ const instance = axios.create({ adapter: createUniAppAxiosAdapter() });
38
52
  ```
39
53
 
40
- ### 上传和下载
54
+ ### 与 [useAxios](https://vueuse.org/integrations/useAxios/) 一起使用
41
55
 
42
56
  ```ts
43
57
  import axios from "axios";
44
58
  import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
45
59
 
46
- const instance = axios.create({
47
- adapter: createUniAppAxiosAdapter(),
48
- });
60
+ axios.defaults.adapter = createUniAppAxiosAdapter();
61
+ const { data, isFinished } = useAxios("/posts");
62
+ ```
49
63
 
50
- // 一个假文件
51
- const data = new File([new Blob()], "emptyFile");
64
+ ### 上传和下载
52
65
 
66
+ ```ts
53
67
  // 下载
54
- instance.download("/");
68
+ axios.download("/");
55
69
  // or
56
- instance.request({
70
+ axios.request({
57
71
  url: "/",
58
72
  method: "download",
59
73
  });
60
74
 
61
75
  // 上传
62
- instance.upload("/", data);
76
+ axios.upload("/", new File([new Blob()], "fake file"));
63
77
  // or
64
- instance.request({
78
+ axios.request({
65
79
  url: "/",
66
80
  method: "upload",
67
- data,
81
+ data: new File([new Blob()], "fake file"),
68
82
  });
69
83
  ```
70
84
 
@@ -84,15 +98,14 @@ export default {
84
98
  ],
85
99
  }
86
100
  ```
101
+
87
102
  > [!WARNING]
88
103
  > 这个插件通过将 `FormData` 和 `Blob` 导出为空 `class`来解决兼容性问题,如果你确实需要的话,使用 `pnpm add miniprogram-formdata miniprogram-blob` 来安装对应的 polyfill 即可,插件会自动使用。
89
104
 
90
105
  如果你使用的是 Vue CLI,改用 `@uni-helper/axios-adapter/webpack` 即可
91
106
 
92
- ## 客户端类型
107
+ ### 版本
93
108
 
94
- 提供了 upload download 方法的类型提示,及 AxiosRequestConfig 支持传递 uniapp 特有参数
109
+ 1.4.0 开始,请始终保持主版本号和次版本号与 axios 一致。例如当你安装了 1.5.1 版本时,你可以安装 axios 的 1.5.x 版本。
95
110
 
96
- ```ts
97
- /// <reference types="@uni-helper/axios-adapter/client" />
98
- ```
111
+ 这样做的目的是始终支持最新的 axios。
package/dist/index.d.cts CHANGED
@@ -1,6 +1,18 @@
1
1
  import { AxiosAdapter } from 'axios';
2
2
  import { U as UserOptions } from './types-76de936f.js';
3
3
 
4
+ declare module "axios" {
5
+ interface AxiosRequestConfig extends Omit<UniApp.RequestOptions, "success" | "fail" | "complete" | "header">, Omit<UniApp.UploadFileOption, "success" | "fail" | "complete" | "header" | "formData">, Omit<UniApp.DownloadFileOption, "success" | "fail" | "complete" | "header">, Partial<Pick<UniApp.RequestTask, "onHeadersReceived">> {
6
+ }
7
+ interface AxiosResponse {
8
+ cookies?: string[];
9
+ }
10
+ interface Axios {
11
+ upload<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
12
+ download<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
13
+ }
14
+ }
15
+
4
16
  declare const createUniAppAxiosAdapter: (userOptions?: UserOptions) => AxiosAdapter;
5
17
 
6
18
  export { createUniAppAxiosAdapter };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,18 @@
1
1
  import { AxiosAdapter } from 'axios';
2
2
  import { U as UserOptions } from './types-76de936f.js';
3
3
 
4
+ declare module "axios" {
5
+ interface AxiosRequestConfig extends Omit<UniApp.RequestOptions, "success" | "fail" | "complete" | "header">, Omit<UniApp.UploadFileOption, "success" | "fail" | "complete" | "header" | "formData">, Omit<UniApp.DownloadFileOption, "success" | "fail" | "complete" | "header">, Partial<Pick<UniApp.RequestTask, "onHeadersReceived">> {
6
+ }
7
+ interface AxiosResponse {
8
+ cookies?: string[];
9
+ }
10
+ interface Axios {
11
+ upload<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
12
+ download<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
13
+ }
14
+ }
15
+
4
16
  declare const createUniAppAxiosAdapter: (userOptions?: UserOptions) => AxiosAdapter;
5
17
 
6
18
  export { createUniAppAxiosAdapter };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uni-helper/axios-adapter",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.5.1",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "kejunmao",
@@ -51,9 +51,6 @@
51
51
  "types": "./dist/webpack.d.cts",
52
52
  "default": "./dist/webpack.cjs"
53
53
  }
54
- },
55
- "./client": {
56
- "types": "./client.d.ts"
57
54
  }
58
55
  },
59
56
  "main": "./dist/index.js",
package/client.d.ts DELETED
@@ -1,35 +0,0 @@
1
- declare module "axios" {
2
- export interface AxiosRequestConfig
3
- extends Omit<
4
- UniApp.RequestOptions,
5
- "success" | "fail" | "complete" | "header"
6
- >,
7
- Omit<
8
- UniApp.UploadFileOption,
9
- "success" | "fail" | "complete" | "header" | "formData"
10
- >,
11
- Omit<
12
- UniApp.DownloadFileOption,
13
- "success" | "fail" | "complete" | "header"
14
- >,
15
- Partial<Pick<UniApp.RequestTask, "onHeadersReceived">> {}
16
-
17
- export interface AxiosResponse {
18
- cookies?: string[];
19
- }
20
-
21
- export interface Axios {
22
- upload<T = any, R = AxiosResponse<T>, D = any>(
23
- url: string,
24
- data?: D,
25
- config?: AxiosRequestConfig<D>
26
- ): Promise<R>;
27
-
28
- download<T = any, R = AxiosResponse<T>, D = any>(
29
- url: string,
30
- config?: AxiosRequestConfig<D>
31
- ): Promise<R>;
32
- }
33
- }
34
-
35
- export {};