From 9e28effdf574482a3bd58cd9b8a258a8f4406a62 Mon Sep 17 00:00:00 2001 From: zjx0905 <954270063@qq.com> Date: Fri, 14 Apr 2023 23:15:49 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=96=B0=E5=A2=9E=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=92=8C=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++ docs/.vitepress/config.ts | 11 +++- docs/.vitepress/theme/styles/cover.css | 2 +- docs/pages/basics/request.md | 71 ++++++++++++++++++++++++++ docs/pages/intro.md | 4 ++ docs/pages/start.md | 16 +++--- 6 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 docs/pages/basics/request.md diff --git a/README.md b/README.md index 866851d..165662f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +--- +editLink: false +--- + # axios-miniprogram
diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 1ba6625..d201744 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -10,12 +10,13 @@ export default defineConfig({ titleTemplate: ':title - axios', description: '基于 Promise 的 HTTP 请求库,适用于各大小程序平台。', srcDir: 'pages', + lastUpdated: true, themeConfig: { // https://vitepress.dev/reference/default-theme-config nav: [ { text: '指南', link: '/intro' }, - { text: '基础', link: '/basics/options' }, + { text: '基础', link: '/basics/request' }, ], sidebar: [ @@ -29,6 +30,7 @@ export default defineConfig({ { text: '基础', items: [ + { text: '发送请求', link: '/basics/request' }, { text: 'OPTIONS 请求', link: '/basics/options' }, { text: 'GET 请求', link: '/basics/get' }, { text: 'HEAD 请求', link: '/basics/head' }, @@ -150,10 +152,17 @@ export default defineConfig({ { icon: 'github', link: 'https://github.com/zjx0905/axios-miniprogram' }, ], + editLink: { + pattern: + 'https://github.com/zjx0905/axios-miniprogram/edit/main/docs/pages/:path', + text: '在 GitHub 上编辑此页面', + }, + returnToTopLabel: '返回顶部', outlineTitle: '导航栏', darkModeSwitchLabel: '主题', sidebarMenuLabel: '菜单', + lastUpdatedText: '最后一次更新', docFooter: { prev: '上一页', next: '下一页', diff --git a/docs/.vitepress/theme/styles/cover.css b/docs/.vitepress/theme/styles/cover.css index ad76e8e..8ae96dc 100644 --- a/docs/.vitepress/theme/styles/cover.css +++ b/docs/.vitepress/theme/styles/cover.css @@ -20,6 +20,7 @@ margin-top: var(--vp-nav-height); padding-top: 40px !important; height: calc(100% - var(--vp-nav-height)); + border-right: 1px solid var(--vp-c-gutter); transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1) !important; } @@ -106,7 +107,6 @@ color: var(--vp-c-link); } -.language-sh, .language-bash, .language-ts { border: 1px solid var(--vp-c-gutter); diff --git a/docs/pages/basics/request.md b/docs/pages/basics/request.md new file mode 100644 index 0000000..8945b96 --- /dev/null +++ b/docs/pages/basics/request.md @@ -0,0 +1,71 @@ +--- +title: 发送请求 +--- + +# {{ $frontmatter.title }} + +::: tip {{ $frontmatter.title }} +发送任意请求方法的 HTTP 请求。 +::: + +## 基础用法 + +您可以直接传入 `url` 发送请求,默认发送的是 `GET` 方法请求。 + +```ts +import axios from 'axios-miniprogram'; + +axios + .request('https://api.com/test') + .then((response) => { + // 成功之后做些什么 + }) + .catch((error) => { + // 失败之后做些什么 + }); +``` + +## 携带自定义配置 + +您也可以传入第二个参数 `config`,用于指定请求方法以及其他配置项。 + +```ts +import axios from 'axios-miniprogram'; + +axios + .request('https://api.com/test', { + method: 'POST', // 此时会发送 POST 方法请求 + data: { + name: 'test', + password: '123456', + }, + }) + .then((response) => { + // 成功之后做些什么 + }) + .catch((error) => { + // 失败之后做些什么 + }); +``` + +## 仅有自定义配置 + +您也可以忽略以上示例,直接传入 `config` 发送请求。 + +```ts +import axios from 'axios-miniprogram'; + +axios + .request({ + url: 'https://api.com/test/:id', + params: { + id: 1, + }, + }) + .then((response) => { + // 成功之后做些什么 + }) + .catch((error) => { + // 失败之后做些什么 + }); +``` diff --git a/docs/pages/intro.md b/docs/pages/intro.md index 866851d..165662f 100644 --- a/docs/pages/intro.md +++ b/docs/pages/intro.md @@ -1,3 +1,7 @@ +--- +editLink: false +--- + # axios-miniprogram
diff --git a/docs/pages/start.md b/docs/pages/start.md index 4912369..43d22e7 100644 --- a/docs/pages/start.md +++ b/docs/pages/start.md @@ -1,9 +1,5 @@ --- title: 快速上手 -sidebarDepth: 1 -lastUpdated: true -sitemap: - priority: 0.8 --- # 快速上手 @@ -12,16 +8,16 @@ sitemap: :::: code-group -```sh [NPM] -npm install -D axios-miniprogram +```bash [NPM] +$ npm install -D axios-miniprogram ``` -```sh [YARN] -yarn add -D axios-miniprogram +```bash [YARN] +$ yarn add -D axios-miniprogram ``` -```sh [PNPM] -pnpm install -D axios-miniprogram +```bash [PNPM] +$ pnpm install -D axios-miniprogram ``` ::::