docs: 新建大纲

pull/41/head
zjx0905 2023-04-16 00:01:40 +08:00
parent b1ce4a37fe
commit ab6fd668c0
25 changed files with 207 additions and 52 deletions

View File

@ -48,8 +48,8 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库
- [QQ 小程序](https://q.qq.com/wiki/develop/miniprogram/frame/?from=axios-miniprogram)
- [钉钉小程序](https://open.dingtalk.com/document/org/develop-org-mini-programs?from=axios-miniprogram)
- [飞书小程序](https://open.feishu.cn/document/uYjL24iN/uMjNzUjLzYzM14yM2MTN?from=axios-miniprogram)
- [快手小程序](https://mp.kuaishou.com/docs/introduction/quickStart.html)
- [uni-app](https://uniapp.dcloud.net.cn?form=axios-miniprogram)
- [快手小程序](https://mp.kuaishou.com/docs/introduction/quickStart.html?from=axios-miniprogram)
- [360 小程序](https://mp.360.cn/doc/miniprogram/dev/#/f4b41f0cc5683bce78dfadfa7f3c73e7?from=axios-miniprogram)
## 关于在跨端框架中使用时的支持度
@ -60,3 +60,7 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库
有问题欢迎反馈,请尽量把问题提到 [github issues](https://github.com/zjx0905/axios-miniprogram/issues) 中,这样更容易被我注意到。
[提问点这里](https://github.com/zjx0905/axios-miniprogram/issues)
## 未来计划
2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除,您可以使用适配器兼容 uni-app。

View File

@ -1,8 +1,8 @@
import { defineConfig } from 'vitepress';
import { VitePWA } from 'vite-plugin-pwa';
import { createIntroMD } from './utils/createIntroMD';
import { linkIntro } from './utils/link-intro';
createIntroMD();
linkIntro();
// https://vitepress.dev/reference/site-config
export default defineConfig({
@ -18,8 +18,13 @@ export default defineConfig({
nav: [
{ text: '指南', link: '/guide/intro', activeMatch: '/guide/' },
{ text: '请求', link: '/request/options', activeMatch: '/request/' },
{ text: '请求方法', link: '/method/OPTIONS', activeMatch: '/method/' },
{ text: '基础', link: '/basics/config', activeMatch: '/basics/' },
{
text: '高级',
link: '/advanced/request-interceptor',
activeMatch: '/advanced/',
},
],
sidebar: sidebar(),
@ -89,17 +94,17 @@ function sidebar() {
],
},
{
text: '请求',
text: '请求方法',
items: [
{ text: 'OPTIONS', link: '/request/OPTIONS' },
{ text: 'GET', link: '/request/GET' },
{ text: 'HEAD', link: '/request/HEAD' },
{ text: 'POST', link: '/request/POST' },
{ text: 'PUT', link: '/request/PUT' },
{ text: 'PATCH', link: '/request/PATCH' },
{ text: 'DELETE', link: '/request/DELETE' },
{ text: 'TRACE', link: '/request/TRACE' },
{ text: 'CONNECT', link: '/request/CONNECT' },
{ 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' },
],
},
{
@ -110,8 +115,21 @@ function sidebar() {
{ text: '发送请求', link: '/basics/request' },
{ text: '上传文件', link: '/basics/upload' },
{ text: '下载文件', link: '/basics/download' },
{ text: '错误处理', link: '/basics/error-handler' },
{ text: '取消请求', link: '/basics/cancel' },
],
},
{
text: '高级',
items: [
{ text: '请求拦截器', link: '/advanced/request-interceptor' },
{ text: '响应拦截器', link: '/advanced/response-interceptor' },
{ text: '创建实例', link: '/advanced/instance' },
{ text: '派生领域', link: '/advanced/fork' },
{ text: '适配器', link: '/advanced/adapter' },
],
},
{
text: '致贡献者',
items: [

View File

@ -13,6 +13,7 @@ interface VPCompatibilityProps {
ks?: Support;
dd?: Support;
jd?: Support;
qh?: Support;
}
const props = defineProps<VPCompatibilityProps>();
@ -27,6 +28,8 @@ const metas = [
{ name: '钉钉小程序', id: 'dd' },
{ name: '飞书小程序', id: 'tt2' },
{ name: '快手小程序', id: 'ks' },
{ name: '360 小程序', id: 'qh' },
];
const platforms = computed(() => {

View File

@ -64,6 +64,7 @@
}
.VPBackdrop {
backdrop-filter: blur(16px);
background-color: transparent !important;
transition: none !important;
}
@ -126,11 +127,7 @@
}
.DocSearch-Container {
backdrop-filter: blur(8px);
}
.DocSearch-Button {
border: 1px solid var(--vp-c-gutter);
backdrop-filter: blur(16px);
}
.DocSearch-Modal {
@ -152,6 +149,12 @@
}
}
@media (min-width: 768px) {
.DocSearch-Button {
border: 1px solid var(--vp-c-gutter);
}
}
@media (min-width: 640px) {
.VPFeatures .item {
width: 100%;

View File

@ -1,9 +1,11 @@
import { copyFileSync } from 'node:fs';
import { linkSync } from 'node:fs';
import { resolve } from '../../../scripts/utils';
const readmePath = resolve('README.md');
const introPath = resolve('docs/pages/guide/intro.md');
export function createIntroMD() {
copyFileSync(readmePath, introPath);
export function linkIntro() {
try {
linkSync(readmePath, introPath);
} catch {}
}

View File

@ -0,0 +1,7 @@
---
title: 适配器
---
# {{ $frontmatter.title }}
待续...

View File

@ -0,0 +1,7 @@
---
title: 派生领域
---
# {{ $frontmatter.title }}
待续...

View File

@ -0,0 +1,7 @@
---
title: 创建实例
---
# {{ $frontmatter.title }}
待续...

View File

@ -0,0 +1,7 @@
---
title: 请求拦截器
---
# {{ $frontmatter.title }}
待续...

View File

@ -0,0 +1,7 @@
---
title: 响应拦截器
---
# {{ $frontmatter.title }}
待续...

View File

@ -0,0 +1,83 @@
---
title: 取消请求
---
# {{ $frontmatter.title }}
::: tip {{ $frontmatter.title }}
用于取消不再需要响应的请求。
:::
## 取消请求
可以创建一个 `CancelToken` 实例用来取消请求。
```ts
import axios from 'axios-miniprogram';
let cancel;
axios
.get('/test', {
cancelToken: new axios.CancelToken((c) => {
// executor 函数接收一个 cancel 函数作为参数
cancel = c;
}),
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
// 取消请求
cancel('request canceled');
```
## 工厂方法
也可以用 `CancelToken.source` 工厂方法创建 `CancelToken` 实例用来取消请求。
```ts
import axios from 'axios-miniprogram';
const { cancel, token } = axios.CancelToken.source();
axios
.get('https://api.com/test', {
cancelToken: token,
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
// 取消请求
cancel('request canceled');
```
## 判断异常是否来自取消请求
也可以用 `axios.isCancel` 判断异常是否来自取消请求,从而做出相应的处理。
```ts
import axios from 'axios-miniprogram';
const { cancel, token } = axios.CancelToken.source();
axios
.get('https://api.com/test', {
cancelToken: token,
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
if (axios.isCancel(error)) {
console.log(error, '请求已被取消');
}
});
// 取消请求
cancel('request canceled');
```

View File

@ -0,0 +1,7 @@
---
title: 错误处理
---
# {{ $frontmatter.title }}
待续...

View File

@ -51,7 +51,7 @@ axios('https//api.com')
```ts
import axios from 'axios-miniprogram';
axios('https//api.com')
axios('https://api.com')
.then((response) => {
const {
// 开发者服务器返回的 cookies格式为字符串数组

View File

@ -17,7 +17,7 @@ import axios from 'axios-miniprogram';
axios
.post(
'https//api.com/test',
'https://api.com/test',
{
// 文件对应的 key开发者在服务端可以通过这个 key 获取文件的二进制内容
name: 'fileName',
@ -49,7 +49,7 @@ import axios from 'axios-miniprogram';
axios
.post(
'https//api.com/test',
'https://api.com/test',
{
// 文件对应的 key开发者在服务端可以通过这个 key 获取文件的二进制内容
name: 'fileName',
@ -87,7 +87,7 @@ import axios from 'axios-miniprogram';
axios
.post(
'https//api.com/test',
'https://api.com/test',
{
// 文件对应的 key开发者在服务端可以通过这个 key 获取文件的二进制内容
name: 'fileName',

View File

@ -108,15 +108,15 @@ axios({
也可以使用请求方法简化请求。
- [axios.request(url, config?) | axios.request(config)](/basics/request)
- [axios.options(url, config?)](/request/OPTIONS)
- [axios.get(url, params?, config?)](/request/GET)
- [axios.head(url, params?, config?)](/request/HEAD)
- [axios.post(url, data?, config?)](/request/POST)
- [axios.put(url, data?, config?)](/request/PUT)
- [axios.patch(url, data?, config?)](/request/PATCH)
- [axios.delete(url, params?, config?)](/request/DELETE)
- [axios.trace(url, config?)](/request/TRACE)
- [axios.connect(url, config?)](/request/CONNECT)
- [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)
还提供了一系列工具方法。

View File

@ -73,4 +73,4 @@ axios
## 兼容性
<VPCompatibility wx my swan tt='1.0.0' qq tt2 />
<VPCompatibility wx my swan tt='1.0.0' qq tt2 qh />

View File

@ -73,4 +73,4 @@ axios
## 兼容性
<VPCompatibility wx my swan jd tt='1.0.0' qq dd tt2 ks />
<VPCompatibility wx my swan jd tt='1.0.0' qq dd tt2 ks qh />

View File

@ -73,4 +73,4 @@ axios
## 兼容性
<VPCompatibility wx swan tt='1.0.0' qq tt2 />
<VPCompatibility wx swan tt='1.0.0' qq tt2 qh />

View File

@ -48,4 +48,4 @@ axios
## 兼容性
<VPCompatibility wx swan tt='1.0.0' qq tt2 />
<VPCompatibility wx swan tt='1.0.0' qq tt2 qh />

View File

@ -75,4 +75,4 @@ axios
## 兼容性
<VPCompatibility wx my swan jd tt='1.0.0' qq dd tt2 ks />
<VPCompatibility wx my swan jd tt='1.0.0' qq dd tt2 ks qh />

View File

@ -77,4 +77,4 @@ axios
## 兼容性
<VPCompatibility wx my swan tt='1.0.0' qq tt2 />
<VPCompatibility wx my swan tt='1.0.0' qq tt2 qh />

20
global.variables.d.ts vendored
View File

@ -1,10 +1,10 @@
declare const uni: unknown;
declare const wx: unknown;
declare const my: unknown;
declare const swan: unknown;
declare const tt: unknown;
declare const qq: unknown;
declare const qh: unknown;
declare const ks: unknown;
declare const dd: unknown;
declare const jd: unknown;
declare const uni: any;
declare const wx: any;
declare const my: any;
declare const swan: any;
declare const tt: any;
declare const qq: any;
declare const qh: any;
declare const ks: any;
declare const dd: any;
declare const jd: any;