feat: 移除内置的 uni 适配器

BREAKING CHANGE :
uni 不再内部支持, 可以参阅文档中的自定义适配器自行适配 uni

#40
pull/49/head
zjx0905 2023-06-04 19:44:32 +08:00
parent 2496333e42
commit 96ea0266dd
6 changed files with 14 additions and 59 deletions

View File

@ -62,6 +62,3 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库
[提问点这里](https://github.com/zjx0905/axios-miniprogram/issues) [提问点这里](https://github.com/zjx0905/axios-miniprogram/issues)
## 未来计划
2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除,您依旧可以使用[适配器](https://axios-miniprogram.com/advanced/adapter)兼容 uni-app。

View File

@ -24,54 +24,17 @@ function getRequest() {
} }
function postRequest() { function postRequest() {
axios.post('/users', { axios.post(
name: 'Leanne Graham', '/users',
username: 'Bret', '{"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"}}',
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() { function putRequest() {
axios.put('/users/:id', { axios.put(
id: 1, '/users/:id',
name: 'Leanne Graham', '{"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"}}',
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() { function deleteRequest() {

View File

@ -1,4 +1,3 @@
declare const uni: any;
declare const wx: any; declare const wx: any;
declare const my: any; declare const my: any;
declare const swan: any; declare const swan: any;

View File

@ -13,13 +13,7 @@ export function getDefaultAdapter() {
function getPlatform() { function getPlatform() {
const undef = 'undefined'; const undef = 'undefined';
if (typeof uni !== undef) { if (typeof wx !== undef) {
return {
request: uni.request,
downloadFile: uni.downloadFile,
uploadFile: uni.uploadFile,
};
} else if (typeof wx !== undef) {
return wx; return wx;
} else if (typeof my !== undef) { } else if (typeof my !== undef) {
return my; return my;

View File

@ -54,8 +54,11 @@ export interface AxiosInstance extends AxiosRequest, Axios {
fork(config: AxiosRequestConfig): AxiosInstance; fork(config: AxiosRequestConfig): AxiosInstance;
} }
export function createInstance(defaults: AxiosRequestConfig, parent?: Axios) { export function createInstance(
const context = new Axios(defaults, parent); defaults: AxiosRequestConfig,
parentContext?: Axios,
) {
const context = new Axios(defaults, parentContext);
const instance = context.request as AxiosInstance; const instance = context.request as AxiosInstance;
instance.getUri = function getUri(config) { instance.getUri = function getUri(config) {

View File

@ -2,7 +2,6 @@ import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest';
import { getDefaultAdapter } from '@/adpater/getDefaultAdapter'; import { getDefaultAdapter } from '@/adpater/getDefaultAdapter';
const platforms = [ const platforms = [
'uni',
'wx', 'wx',
'my', 'my',
'swan', 'swan',