Skip to content

Commit

Permalink
docs: drop english
Browse files Browse the repository at this point in the history
  • Loading branch information
nei1ee committed Apr 14, 2023
1 parent 153441c commit 58625c1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 127 deletions.
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

# @uni-helper/axios-adapter

> Uniapp Axios Adapter for Vue2 and Vue3.
> 适用于 Vue2 和 Vue3 的 uniapp Axios 适配器
English | [简体中文](./README.zh-CN.md)

## Installation
## 安装

```
pnpm i @uni-helper/axios-adapter axios
```

## Usage
## 使用

### Basic Usage
### 基本用法

```ts
import axios from "axios";
Expand All @@ -25,7 +23,7 @@ const instance = axios.create({
});
```

### with useAxios
### useAxios 一起使用

```ts
import axios from "axios";
Expand All @@ -39,7 +37,7 @@ const instance = axios.create({
const { data, isFinished } = useAxios("/posts", instance);
```

### Upload and Download
### 上传和下载

```ts
import axios from "axios";
Expand All @@ -49,18 +47,18 @@ const instance = axios.create({
adapter: createUniAppAxiosAdapter(),
});

// a fake file
// 一个假文件
const data = new File([new Blob()], "emptyFile");

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

// upload
// 上传
instance.upload("/", data);
// or
instance.request({
Expand All @@ -70,7 +68,45 @@ instance.request({
});
```

## Client Types
### 小程序
小程序没有 FormData 和 Blob 对象, 因此你需要额外的库来兼容,并通过自定义一个 vite 插件来兼容

```bash
pnpm add miniprogram-formdata miniprogram-blob
```

```ts
// vite.config.ts
export default defineConfig({
plugins: [
{
transform(code, id) {
if (process.env.UNI_PLATFORM?.includes("mp")) {
if (id.includes("/form-data/lib/browser.js")) {
return {
code: code.replace("window", "globalThis"),
};
}
if (id.includes("/axios/lib/platform/browser/classes/FormData.js")) {
return {
code: `import FormData from 'miniprogram-formdata';\nexport default FormData;`,
};
}
if (id.includes("/axios/lib/platform/browser/index.js")) {
return {
code: `import Blob from 'miniprogram-blob'\n${code}`,
};
}
}
},
},
]
})
```

## 客户端类型

提供了 upload 和 download 方法的类型提示,及 AxiosRequestConfig 支持传递 uniapp 特有参数

```ts
/// <reference types="@uni-helper/axios-adapter/client" />
Expand Down
115 changes: 0 additions & 115 deletions README.zh-CN.md

This file was deleted.

0 comments on commit 58625c1

Please sign in to comment.