Skip to content

Commit

Permalink
feat: 移除内置的 uni 适配器
Browse files Browse the repository at this point in the history
BREAKING CHANGE :
uni 不再内部支持, 可以参阅文档中的自定义适配器自行适配 uni

#40
  • Loading branch information
zjxxxxxxxxx committed Jun 4, 2023
1 parent 2496333 commit 96ea026
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 59 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,3 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库

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

## 未来计划

2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除,您依旧可以使用[适配器](https://axios-miniprogram.com/advanced/adapter)兼容 uni-app。
53 changes: 8 additions & 45 deletions example/src/pages/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,17 @@ function getRequest() {
}
function postRequest() {
axios.post('/users', {
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',
},
});
axios.post(
'/users',
'{"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"}}',
);
}
function putRequest() {
axios.put('/users/:id', {
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',
},
});
axios.put(
'/users/:id',
'{"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"}}',
);
}
function deleteRequest() {
Expand Down
1 change: 0 additions & 1 deletion global.variables.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
declare const uni: any;
declare const wx: any;
declare const my: any;
declare const swan: any;
Expand Down
8 changes: 1 addition & 7 deletions src/adpater/getDefaultAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ export function getDefaultAdapter() {
function getPlatform() {
const undef = 'undefined';

if (typeof uni !== undef) {
return {
request: uni.request,
downloadFile: uni.downloadFile,
uploadFile: uni.uploadFile,
};
} else if (typeof wx !== undef) {
if (typeof wx !== undef) {
return wx;
} else if (typeof my !== undef) {
return my;
Expand Down
7 changes: 5 additions & 2 deletions src/core/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ export interface AxiosInstance extends AxiosRequest, Axios {
fork(config: AxiosRequestConfig): AxiosInstance;
}

export function createInstance(defaults: AxiosRequestConfig, parent?: Axios) {
const context = new Axios(defaults, parent);
export function createInstance(
defaults: AxiosRequestConfig,
parentContext?: Axios,
) {
const context = new Axios(defaults, parentContext);
const instance = context.request as AxiosInstance;

instance.getUri = function getUri(config) {
Expand Down
1 change: 0 additions & 1 deletion test/adpater/getDefaultAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest';
import { getDefaultAdapter } from '@/adpater/getDefaultAdapter';

const platforms = [
'uni',
'wx',
'my',
'swan',
Expand Down

0 comments on commit 96ea026

Please sign in to comment.