docs: 新建大纲
parent
b1ce4a37fe
commit
ab6fd668c0
|
@ -48,8 +48,8 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库
|
||||||
- [QQ 小程序](https://q.qq.com/wiki/develop/miniprogram/frame/?from=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.dingtalk.com/document/org/develop-org-mini-programs?from=axios-miniprogram)
|
||||||
- [飞书小程序](https://open.feishu.cn/document/uYjL24iN/uMjNzUjLzYzM14yM2MTN?from=axios-miniprogram)
|
- [飞书小程序](https://open.feishu.cn/document/uYjL24iN/uMjNzUjLzYzM14yM2MTN?from=axios-miniprogram)
|
||||||
- [快手小程序](https://mp.kuaishou.com/docs/introduction/quickStart.html)
|
- [快手小程序](https://mp.kuaishou.com/docs/introduction/quickStart.html?from=axios-miniprogram)
|
||||||
- [uni-app](https://uniapp.dcloud.net.cn?form=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) 中,这样更容易被我注意到。
|
有问题欢迎反馈,请尽量把问题提到 [github issues](https://github.com/zjx0905/axios-miniprogram/issues) 中,这样更容易被我注意到。
|
||||||
|
|
||||||
[提问点这里](https://github.com/zjx0905/axios-miniprogram/issues)
|
[提问点这里](https://github.com/zjx0905/axios-miniprogram/issues)
|
||||||
|
|
||||||
|
## 未来计划
|
||||||
|
|
||||||
|
2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除,您可以使用适配器兼容 uni-app。
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { defineConfig } from 'vitepress';
|
import { defineConfig } from 'vitepress';
|
||||||
import { VitePWA } from 'vite-plugin-pwa';
|
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
|
// https://vitepress.dev/reference/site-config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
@ -18,8 +18,13 @@ export default defineConfig({
|
||||||
|
|
||||||
nav: [
|
nav: [
|
||||||
{ text: '指南', link: '/guide/intro', activeMatch: '/guide/' },
|
{ 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: '/basics/config', activeMatch: '/basics/' },
|
||||||
|
{
|
||||||
|
text: '高级',
|
||||||
|
link: '/advanced/request-interceptor',
|
||||||
|
activeMatch: '/advanced/',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
sidebar: sidebar(),
|
sidebar: sidebar(),
|
||||||
|
@ -89,17 +94,17 @@ function sidebar() {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '请求',
|
text: '请求方法',
|
||||||
items: [
|
items: [
|
||||||
{ text: 'OPTIONS', link: '/request/OPTIONS' },
|
{ text: 'OPTIONS', link: '/method/OPTIONS' },
|
||||||
{ text: 'GET', link: '/request/GET' },
|
{ text: 'GET', link: '/method/GET' },
|
||||||
{ text: 'HEAD', link: '/request/HEAD' },
|
{ text: 'HEAD', link: '/method/HEAD' },
|
||||||
{ text: 'POST', link: '/request/POST' },
|
{ text: 'POST', link: '/method/POST' },
|
||||||
{ text: 'PUT', link: '/request/PUT' },
|
{ text: 'PUT', link: '/method/PUT' },
|
||||||
{ text: 'PATCH', link: '/request/PATCH' },
|
{ text: 'PATCH', link: '/method/PATCH' },
|
||||||
{ text: 'DELETE', link: '/request/DELETE' },
|
{ text: 'DELETE', link: '/method/DELETE' },
|
||||||
{ text: 'TRACE', link: '/request/TRACE' },
|
{ text: 'TRACE', link: '/method/TRACE' },
|
||||||
{ text: 'CONNECT', link: '/request/CONNECT' },
|
{ text: 'CONNECT', link: '/method/CONNECT' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -110,8 +115,21 @@ function sidebar() {
|
||||||
{ text: '发送请求', link: '/basics/request' },
|
{ text: '发送请求', link: '/basics/request' },
|
||||||
{ text: '上传文件', link: '/basics/upload' },
|
{ text: '上传文件', link: '/basics/upload' },
|
||||||
{ text: '下载文件', link: '/basics/download' },
|
{ 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: '致贡献者',
|
text: '致贡献者',
|
||||||
items: [
|
items: [
|
||||||
|
|
|
@ -13,6 +13,7 @@ interface VPCompatibilityProps {
|
||||||
ks?: Support;
|
ks?: Support;
|
||||||
dd?: Support;
|
dd?: Support;
|
||||||
jd?: Support;
|
jd?: Support;
|
||||||
|
qh?: Support;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<VPCompatibilityProps>();
|
const props = defineProps<VPCompatibilityProps>();
|
||||||
|
@ -27,6 +28,8 @@ const metas = [
|
||||||
{ name: '钉钉小程序', id: 'dd' },
|
{ name: '钉钉小程序', id: 'dd' },
|
||||||
{ name: '飞书小程序', id: 'tt2' },
|
{ name: '飞书小程序', id: 'tt2' },
|
||||||
{ name: '快手小程序', id: 'ks' },
|
{ name: '快手小程序', id: 'ks' },
|
||||||
|
{ name: '360 小程序', id: 'qh' },
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const platforms = computed(() => {
|
const platforms = computed(() => {
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.VPBackdrop {
|
.VPBackdrop {
|
||||||
|
backdrop-filter: blur(16px);
|
||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
transition: none !important;
|
transition: none !important;
|
||||||
}
|
}
|
||||||
|
@ -126,11 +127,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.DocSearch-Container {
|
.DocSearch-Container {
|
||||||
backdrop-filter: blur(8px);
|
backdrop-filter: blur(16px);
|
||||||
}
|
|
||||||
|
|
||||||
.DocSearch-Button {
|
|
||||||
border: 1px solid var(--vp-c-gutter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.DocSearch-Modal {
|
.DocSearch-Modal {
|
||||||
|
@ -152,6 +149,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.DocSearch-Button {
|
||||||
|
border: 1px solid var(--vp-c-gutter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 640px) {
|
@media (min-width: 640px) {
|
||||||
.VPFeatures .item {
|
.VPFeatures .item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { copyFileSync } from 'node:fs';
|
import { linkSync } from 'node:fs';
|
||||||
import { resolve } from '../../../scripts/utils';
|
import { resolve } from '../../../scripts/utils';
|
||||||
|
|
||||||
const readmePath = resolve('README.md');
|
const readmePath = resolve('README.md');
|
||||||
const introPath = resolve('docs/pages/guide/intro.md');
|
const introPath = resolve('docs/pages/guide/intro.md');
|
||||||
|
|
||||||
export function createIntroMD() {
|
export function linkIntro() {
|
||||||
copyFileSync(readmePath, introPath);
|
try {
|
||||||
|
linkSync(readmePath, introPath);
|
||||||
|
} catch {}
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
title: 适配器
|
||||||
|
---
|
||||||
|
|
||||||
|
# {{ $frontmatter.title }}
|
||||||
|
|
||||||
|
待续...
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
title: 派生领域
|
||||||
|
---
|
||||||
|
|
||||||
|
# {{ $frontmatter.title }}
|
||||||
|
|
||||||
|
待续...
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
title: 创建实例
|
||||||
|
---
|
||||||
|
|
||||||
|
# {{ $frontmatter.title }}
|
||||||
|
|
||||||
|
待续...
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
title: 请求拦截器
|
||||||
|
---
|
||||||
|
|
||||||
|
# {{ $frontmatter.title }}
|
||||||
|
|
||||||
|
待续...
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
title: 响应拦截器
|
||||||
|
---
|
||||||
|
|
||||||
|
# {{ $frontmatter.title }}
|
||||||
|
|
||||||
|
待续...
|
|
@ -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');
|
||||||
|
```
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
title: 错误处理
|
||||||
|
---
|
||||||
|
|
||||||
|
# {{ $frontmatter.title }}
|
||||||
|
|
||||||
|
待续...
|
|
@ -51,7 +51,7 @@ axios('https//api.com')
|
||||||
```ts
|
```ts
|
||||||
import axios from 'axios-miniprogram';
|
import axios from 'axios-miniprogram';
|
||||||
|
|
||||||
axios('https//api.com')
|
axios('https://api.com')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const {
|
const {
|
||||||
// 开发者服务器返回的 cookies,格式为字符串数组
|
// 开发者服务器返回的 cookies,格式为字符串数组
|
||||||
|
|
|
@ -17,7 +17,7 @@ import axios from 'axios-miniprogram';
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
'https//api.com/test',
|
'https://api.com/test',
|
||||||
{
|
{
|
||||||
// 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
// 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
||||||
name: 'fileName',
|
name: 'fileName',
|
||||||
|
@ -49,7 +49,7 @@ import axios from 'axios-miniprogram';
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
'https//api.com/test',
|
'https://api.com/test',
|
||||||
{
|
{
|
||||||
// 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
// 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
||||||
name: 'fileName',
|
name: 'fileName',
|
||||||
|
@ -87,7 +87,7 @@ import axios from 'axios-miniprogram';
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
'https//api.com/test',
|
'https://api.com/test',
|
||||||
{
|
{
|
||||||
// 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
// 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
|
||||||
name: 'fileName',
|
name: 'fileName',
|
||||||
|
|
|
@ -108,15 +108,15 @@ axios({
|
||||||
也可以使用请求方法简化请求。
|
也可以使用请求方法简化请求。
|
||||||
|
|
||||||
- [axios.request(url, config?) | axios.request(config)](/basics/request)
|
- [axios.request(url, config?) | axios.request(config)](/basics/request)
|
||||||
- [axios.options(url, config?)](/request/OPTIONS)
|
- [axios.options(url, config?)](/method/OPTIONS)
|
||||||
- [axios.get(url, params?, config?)](/request/GET)
|
- [axios.get(url, params?, config?)](/method/GET)
|
||||||
- [axios.head(url, params?, config?)](/request/HEAD)
|
- [axios.head(url, params?, config?)](/method/HEAD)
|
||||||
- [axios.post(url, data?, config?)](/request/POST)
|
- [axios.post(url, data?, config?)](/method/POST)
|
||||||
- [axios.put(url, data?, config?)](/request/PUT)
|
- [axios.put(url, data?, config?)](/method/PUT)
|
||||||
- [axios.patch(url, data?, config?)](/request/PATCH)
|
- [axios.patch(url, data?, config?)](/method/PATCH)
|
||||||
- [axios.delete(url, params?, config?)](/request/DELETE)
|
- [axios.delete(url, params?, config?)](/method/DELETE)
|
||||||
- [axios.trace(url, config?)](/request/TRACE)
|
- [axios.trace(url, config?)](/method/TRACE)
|
||||||
- [axios.connect(url, config?)](/request/CONNECT)
|
- [axios.connect(url, config?)](/method/CONNECT)
|
||||||
|
|
||||||
还提供了一系列工具方法。
|
还提供了一系列工具方法。
|
||||||
|
|
||||||
|
|
|
@ -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 />
|
|
@ -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 />
|
|
@ -73,4 +73,4 @@ axios
|
||||||
|
|
||||||
## 兼容性
|
## 兼容性
|
||||||
|
|
||||||
<VPCompatibility wx swan tt='1.0.0' qq tt2 />
|
<VPCompatibility wx swan tt='1.0.0' qq tt2 qh />
|
|
@ -48,4 +48,4 @@ axios
|
||||||
|
|
||||||
## 兼容性
|
## 兼容性
|
||||||
|
|
||||||
<VPCompatibility wx swan tt='1.0.0' qq tt2 />
|
<VPCompatibility wx swan tt='1.0.0' qq tt2 qh />
|
|
@ -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 />
|
|
@ -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 />
|
|
@ -1,10 +1,10 @@
|
||||||
declare const uni: unknown;
|
declare const uni: any;
|
||||||
declare const wx: unknown;
|
declare const wx: any;
|
||||||
declare const my: unknown;
|
declare const my: any;
|
||||||
declare const swan: unknown;
|
declare const swan: any;
|
||||||
declare const tt: unknown;
|
declare const tt: any;
|
||||||
declare const qq: unknown;
|
declare const qq: any;
|
||||||
declare const qh: unknown;
|
declare const qh: any;
|
||||||
declare const ks: unknown;
|
declare const ks: any;
|
||||||
declare const dd: unknown;
|
declare const dd: any;
|
||||||
declare const jd: unknown;
|
declare const jd: any;
|
||||||
|
|
Loading…
Reference in New Issue