Skip to content

Commit

Permalink
feat: 添加版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
zjxxxxxxxxx committed Apr 19, 2023
1 parent 5469471 commit e3346a8
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 185 deletions.
15 changes: 8 additions & 7 deletions README.md
Expand Up @@ -28,15 +28,16 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库

- 支持 `Typescript`,健全的类型系统,智能的 `IDE` 提示。
- 支持 `Promise`
- 支持 拦截器。
- 支持 取消请求。
- 支持 自定义合法状态码。
- 支持 自定义参数序列化。
- 支持 自定义转换数据。
- 支持 自定义错误处理。
- 支持 自定义平台适配器。
- 支持 动态地址。
- 支持 校验状态码。
- 支持 参数序列化。
- 支持 上传/下载。
- 支持 错误处理。
- 支持 转换数据。
- 支持 取消请求。
- 支持 拦截器。
- 支持 派生领域。
- 支持 适配器。

## 目前内部支持的平台

Expand Down
53 changes: 28 additions & 25 deletions docs/.vitepress/config.ts
Expand Up @@ -18,13 +18,13 @@ export default defineConfig({

nav: [
{ text: '指南', link: '/guide/intro', activeMatch: '/guide/' },
{ text: '请求方法', link: '/method/OPTIONS', activeMatch: '/method/' },
{ text: '基础', link: '/basics/config', activeMatch: '/basics/' },
{ text: '入门', link: '/basics/request', activeMatch: '/basics/' },
{
text: '高级',
text: '进阶',
link: '/advanced/request-interceptor',
activeMatch: '/advanced/',
},
{ text: '请求方法', link: '/method/OPTIONS', activeMatch: '/method/' },
],

sidebar: sidebar(),
Expand Down Expand Up @@ -93,50 +93,53 @@ function sidebar() {
{ text: '开始', link: '/guide/quick-start' },
],
},

{
text: '请求方法',
items: [
{ text: 'OPTIONS', link: '/method/OPTIONS' },
{ text: 'GET', link: '/method/GET' },
{ text: 'HEAD', link: '/method/HEAD' },
{ text: 'POST', link: '/method/POST' },
{ text: 'PUT', link: '/method/PUT' },
{ text: 'PATCH', link: '/method/PATCH' },
{ text: 'DELETE', link: '/method/DELETE' },
{ text: 'TRACE', link: '/method/TRACE' },
{ text: 'CONNECT', link: '/method/CONNECT' },
],
collapsed: false,
},
{
text: '基础',
text: '入门',
items: [
{ text: '请求配置', link: '/basics/config' },
{ text: '默认配置', link: '/basics/defaults' },
{ text: '响应体', link: '/basics/response' },
{ text: '发送请求', link: '/basics/request' },
{ text: '响应体', link: '/basics/response' },
{ text: '错误处理', link: '/basics/error-handler' },
{ text: '动态地址', link: '/basics/dynamic-url' },
{ text: '请求配置', link: '/basics/config' },
{ text: '默认配置', link: '/basics/defaults' },
{ text: '参数系列化', link: '/basics/params-serializer' },
{ text: '转换数据', link: '/basics/transform-data' },
{ text: '下载文件', link: '/basics/download' },
{ text: '上传文件', link: '/basics/upload' },
{ text: '错误处理', link: '/basics/error-handler' },
{ text: '取消请求', link: '/basics/cancel' },
],
collapsed: false,
},

{
text: '高级',
text: '进阶',
items: [
{ text: '请求拦截器', link: '/advanced/request-interceptor' },
{ text: '响应拦截器', link: '/advanced/response-interceptor' },
{ text: '取消请求', link: '/advanced/cancel' },
{ text: '创建实例', link: '/advanced/instance' },
{ text: '派生领域', link: '/advanced/fork' },
{ text: '平台适配器', link: '/advanced/adapter' },
],
collapsed: false,
},

{
text: '请求方法',
items: [
{ text: 'OPTIONS', link: '/method/OPTIONS' },
{ text: 'GET', link: '/method/GET' },
{ text: 'HEAD', link: '/method/HEAD' },
{ text: 'POST', link: '/method/POST' },
{ text: 'PUT', link: '/method/PUT' },
{ text: 'PATCH', link: '/method/PATCH' },
{ text: 'DELETE', link: '/method/DELETE' },
{ text: 'TRACE', link: '/method/TRACE' },
{ text: 'CONNECT', link: '/method/CONNECT' },
],
collapsed: false,
},

{
text: '致贡献者',
items: [
Expand Down
8 changes: 8 additions & 0 deletions docs/.vitepress/theme/styles/cover.css
Expand Up @@ -170,6 +170,10 @@
box-shadow: none;
}

.DocSearch-Logo svg > * {
fill: currentColor;
}

.custom-block {
border-radius: 6px;
background-color: var(--vp-custom-block-tip-bg) !important;
Expand All @@ -183,6 +187,10 @@
background-color: var(--vp-code-block-bg);
}

.dark .DocSearch-Logo svg > * {
fill: currentColor;
}

@media (min-width: 960px) {
.VPFeatures .item {
width: calc(100% / 2) !important;
Expand Down
9 changes: 7 additions & 2 deletions docs/.vitepress/theme/styles/vars.css
Expand Up @@ -39,7 +39,8 @@
--vp-custom-block-tip-text: var(--vp-c-brand);
--vp-custom-block-tip-bg: var(--vp-c-bg);

--docsearch-container-background: rgba(0, 0, 0, 0.1);
--docsearch-container-background: rgba(0, 0, 0, 0.02);
--docsearch-logo-color: var(--vp-c-brand);

--vp-sidebar-width: 340px;
}
Expand Down Expand Up @@ -67,5 +68,9 @@
--vp-code-copy-code-border-color: rgba(240, 246, 252, 0.1);
--vp-code-copy-code-hover-border-color: #8b949e;

--docsearch-container-background: rgba(255, 255, 255, 0.1);
--docsearch-container-background: rgba(255, 255, 255, 0.08);
}

.dark .DocSearch {
--docsearch-logo-color: var(--vp-c-brand);
}
File renamed without changes.
6 changes: 5 additions & 1 deletion docs/pages/basics/defaults.md
Expand Up @@ -168,6 +168,10 @@ axios.interceptors.response.use((response) => {

默认配置和请求配置将会按优先级进行合并。

其中 `url``method``data``upload``download` 只从 `config` 取值,`headers``params` 会进行深度合并,其余属性则会优先从 `config` 取值。
其中:

1. `url``method``data``upload``download` 只从 `config` 取值。
2. `headers``params` 会分别进行深度合并。
3. 其余属性则会优先从 `config` 取值。

具体配置合并策略请参阅 [mergeConfig.ts](https://github.com/zjx0905/axios-miniprogram/blob/main/src/core/mergeConfig.ts)
73 changes: 32 additions & 41 deletions docs/pages/basics/download.md
Expand Up @@ -5,7 +5,11 @@ title: 下载文件
# {{ $frontmatter.title }}

::: tip {{ $frontmatter.title }}
下载文件资源到本地,必须使用 `GET` 方法请求,并将配置项 `download` 设置为 `true`
下载文件资源到本地。
:::

::: warning 注意
下载文件只能使用 `GET` 方法请求,并将配置项 `download` 设置为 `true`
:::

## 普通的下载请求
Expand All @@ -15,14 +19,9 @@ title: 下载文件
```ts
import axios from 'axios-miniprogram';

axios
.get(
'https://api.com/test',
{},
{
download: true,
},
)
axios('https://api.com/test', {
download: true,
})
.then((response) => {
const {
// 临时文件路径 (本地路径)。没传入 filePath 指定文件存储路径时会返回,下载后的文件会存储到一个临时文件
Expand All @@ -41,16 +40,12 @@ axios
```ts
import axios from 'axios-miniprogram';

axios
.get(
'https://api.com/test',
{
filePath: '你的本地路径',
},
{
download: true,
},
)
axios('https://api.com/test', {
download: true,
params: {
filePath: '你的本地路径',
},
})
.then((response) => {
const {
// 指定文件下载后存储的路径 (本地路径)
Expand All @@ -69,28 +64,24 @@ axios
```ts
import axios from 'axios-miniprogram';

axios
.get(
'https://api.com/test',
{
filePath: '你的本地路径',
},
{
download: true,
onDownloadProgress(event) {
const {
// 下载进度
progress,

// 已经下载的数据长度
totalBytesSent,

// 预期需要下载的数据总长度
totalBytesExpectedToSend,
} = event;
},
},
)
axios('https://api.com/test', {
download: true,
params: {
filePath: '你的本地路径',
},
onDownloadProgress(event) {
const {
// 下载进度
progress,

// 已经下载的数据长度
totalBytesSent,

// 预期需要下载的数据总长度
totalBytesExpectedToSend,
} = event;
},
})
.then((response) => {
const {
// 指定文件下载后存储的路径 (本地路径)
Expand Down
14 changes: 14 additions & 0 deletions docs/pages/basics/request.md
Expand Up @@ -70,6 +70,20 @@ axios
});
```

## 请求方法

提供一系列基于 `axios.request()` 的请求方法,可以使用请求方法简化请求。

- [axios.options(url, config?)](/method/OPTIONS)
- [axios.get(url, params?, config?)](/method/GET)
- [axios.head(url, params?, config?)](/method/HEAD)
- [axios.post(url, data?, config?)](/method/POST)
- [axios.put(url, data?, config?)](/method/PUT)
- [axios.patch(url, data?, config?)](/method/PATCH)
- [axios.delete(url, params?, config?)](/method/DELETE)
- [axios.trace(url, config?)](/method/TRACE)
- [axios.connect(url, config?)](/method/CONNECT)

## 说明

您可能发现 `axios.request()``axios()` 使用方式完全一致,为什么用法是一样的?
Expand Down
32 changes: 28 additions & 4 deletions docs/pages/basics/transform-data.md
Expand Up @@ -20,7 +20,13 @@ axios('test', {
transformRequest(data, headers) {
return JSON.stringify(data);
},
});
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```

也支持多次转换。
Expand All @@ -38,7 +44,13 @@ axios('test', {
return encodeURIComponent(data);
},
],
});
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```

## 全局转换请求数据
Expand All @@ -64,7 +76,13 @@ axios('test', {
transformResponse(data, headers) {
return JSON.parse(data);
},
});
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```

也支持多次转换。
Expand All @@ -81,7 +99,13 @@ axios('test', {
return JSON.parse(data);
},
],
});
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```

## 全局转换响应数据
Expand Down

0 comments on commit e3346a8

Please sign in to comment.