Skip to content

Commit 96ea026

Browse files
committed
feat: 移除内置的 uni 适配器
BREAKING CHANGE : uni 不再内部支持, 可以参阅文档中的自定义适配器自行适配 uni #40
1 parent 2496333 commit 96ea026

File tree

6 files changed

+14
-59
lines changed

6 files changed

+14
-59
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,3 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库
6262

6363
[提问点这里](https://github.com/zjx0905/axios-miniprogram/issues)
6464

65-
## 未来计划
66-
67-
2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除,您依旧可以使用[适配器](https://axios-miniprogram.com/advanced/adapter)兼容 uni-app。

example/src/pages/index/index.vue

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,17 @@ function getRequest() {
2424
}
2525
2626
function postRequest() {
27-
axios.post('/users', {
28-
name: 'Leanne Graham',
29-
username: 'Bret',
30-
email: 'Sincere@april.biz',
31-
address: {
32-
street: 'Kulas Light',
33-
suite: 'Apt. 556',
34-
city: 'Gwenborough',
35-
zipcode: '92998-3874',
36-
geo: {
37-
lat: '-37.3159',
38-
lng: '81.1496',
39-
},
40-
},
41-
phone: '1-770-736-8031 x56442',
42-
website: 'hildegard.org',
43-
company: {
44-
name: 'Romaguera-Crona',
45-
catchPhrase: 'Multi-layered client-server neural-net',
46-
bs: 'harness real-time e-markets',
47-
},
48-
});
27+
axios.post(
28+
'/users',
29+
'{"name":"Leanne Graham","username":"Bret","email":"Sincere@april.biz","address":{"street":"Kulas Light","suite":"Apt. 556","city":"Gwenborough","zipcode":"92998-3874","geo":{"lat":"-37.3159","lng":"81.1496"}},"phone":"1-770-736-8031 x56442","website":"hildegard.org","company":{"name":"Romaguera-Crona","catchPhrase":"Multi-layered client-server neural-net","bs":"harness real-time e-markets"}}',
30+
);
4931
}
5032
5133
function putRequest() {
52-
axios.put('/users/:id', {
53-
id: 1,
54-
name: 'Leanne Graham',
55-
username: 'Bret',
56-
email: 'Sincere@april.biz',
57-
address: {
58-
street: 'Kulas Light',
59-
suite: 'Apt. 556',
60-
city: 'Gwenborough',
61-
zipcode: '92998-3874',
62-
geo: {
63-
lat: '-37.3159',
64-
lng: '81.1496',
65-
},
66-
},
67-
phone: '1-770-736-8031 x56442',
68-
website: 'hildegard.org',
69-
company: {
70-
name: 'Romaguera-Crona',
71-
catchPhrase: 'Multi-layered client-server neural-net',
72-
bs: 'harness real-time e-markets',
73-
},
74-
});
34+
axios.put(
35+
'/users/:id',
36+
'{"id":1,"name":"Leanne Graham","username":"Bret","email":"Sincere@april.biz","address":{"street":"Kulas Light","suite":"Apt. 556","city":"Gwenborough","zipcode":"92998-3874","geo":{"lat":"-37.3159","lng":"81.1496"}},"phone":"1-770-736-8031 x56442","website":"hildegard.org","company":{"name":"Romaguera-Crona","catchPhrase":"Multi-layered client-server neural-net","bs":"harness real-time e-markets"}}',
37+
);
7538
}
7639
7740
function deleteRequest() {

global.variables.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
declare const uni: any;
21
declare const wx: any;
32
declare const my: any;
43
declare const swan: any;

src/adpater/getDefaultAdapter.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ export function getDefaultAdapter() {
1313
function getPlatform() {
1414
const undef = 'undefined';
1515

16-
if (typeof uni !== undef) {
17-
return {
18-
request: uni.request,
19-
downloadFile: uni.downloadFile,
20-
uploadFile: uni.uploadFile,
21-
};
22-
} else if (typeof wx !== undef) {
16+
if (typeof wx !== undef) {
2317
return wx;
2418
} else if (typeof my !== undef) {
2519
return my;

src/core/createInstance.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ export interface AxiosInstance extends AxiosRequest, Axios {
5454
fork(config: AxiosRequestConfig): AxiosInstance;
5555
}
5656

57-
export function createInstance(defaults: AxiosRequestConfig, parent?: Axios) {
58-
const context = new Axios(defaults, parent);
57+
export function createInstance(
58+
defaults: AxiosRequestConfig,
59+
parentContext?: Axios,
60+
) {
61+
const context = new Axios(defaults, parentContext);
5962
const instance = context.request as AxiosInstance;
6063

6164
instance.getUri = function getUri(config) {

test/adpater/getDefaultAdapter.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest';
22
import { getDefaultAdapter } from '@/adpater/getDefaultAdapter';
33

44
const platforms = [
5-
'uni',
65
'wx',
76
'my',
87
'swan',

0 commit comments

Comments
 (0)