Skip to content

Commit 2f2bdb5

Browse files
committed
docs: add client-api reference
1 parent e29b6e1 commit 2f2bdb5

File tree

3 files changed

+237
-3
lines changed

3 files changed

+237
-3
lines changed

docs/reference/client-api.md

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,120 @@
11
# Client API
22

3-
> TODO
3+
Client API is provided by [@vuepress/client](https://www.npmjs.com/package/@vuepress/client) package, which is used for developing client files.
4+
5+
## Composition API
6+
7+
### useSiteData
8+
9+
- Details:
10+
11+
Returns the site data ref object.
12+
13+
### useSiteLocaleData
14+
15+
- Details:
16+
17+
Returns the site data ref object of current locale.
18+
19+
The properties of current locale have been merged into the root-level properties.
20+
21+
### useRouteLocale
22+
23+
- Details:
24+
25+
Returns the locale path ref object of current route.
26+
27+
The value is one of the keys of the [locales](./config.md#locales) config.
28+
29+
### usePageData
30+
31+
- Details:
32+
33+
Returns the page data ref object of current page.
34+
35+
### usePageFrontmatter
36+
37+
- Details:
38+
39+
Returns the frontmatter ref object of current page.
40+
41+
The value is the `frontmatter` property of the page data.
42+
43+
### usePageHead
44+
45+
- Details:
46+
47+
Returns the head config ref object of current page.
48+
49+
The value is obtained by merging and deduplicating [head](./frontmatter.md#head) frontmatter and [head](./config.md#head) config.
50+
51+
### usePageHeadTitle
52+
53+
- Details:
54+
55+
Returns the head title ref object of current page.
56+
57+
The value is obtained by joining the page title and site title.
58+
59+
### usePageLang
60+
61+
- Details:
62+
63+
Returns the language ref object of current page.
64+
65+
The value is the `lang` property of the page data.
66+
67+
## Utils
68+
69+
### withBase
70+
71+
- Details:
72+
73+
Prefix URL with site [base](./config.md#base).
74+
75+
- Also see:
76+
- [Guide > Assets > Base Helper](../guide/assets.md#base-helper)
77+
78+
## Types
79+
80+
In addition to the type helpers mentioned below, we also provide type definitions related to the above composition API, such as `SiteData` and `PageData`.
81+
82+
### ClientAppSetup
83+
84+
- Details:
85+
86+
Type helper for [clientAppSetupFiles](./plugin-api.md#clientappsetupfiles).
87+
88+
- Example:
89+
90+
Create `clientAppSetup.ts` file:
91+
92+
```ts
93+
import type { ClientAppSetup } from '@vuepress/client'
94+
95+
const clientAppSetup: ClientAppSetup = () => {
96+
// ...
97+
}
98+
99+
export default clientAppSetup
100+
```
101+
102+
### ClientAppEnhance
103+
104+
- Details:
105+
106+
Type helper for [clientAppEnhanceFiles](./plugin-api.md#clientappenhancefiles).
107+
108+
- Example:
109+
110+
Create `clientAppEnhance.ts` file:
111+
112+
```ts
113+
import type { ClientAppEnhance } from '@vuepress/client'
114+
115+
const clientAppEnhance: ClientAppEnhance = ({ app, router, siteData }) => {
116+
// ...
117+
}
118+
119+
export default clientAppEnhance
120+
```

docs/reference/plugin/theme-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default {
8282

8383
Returns the theme data ref object in current locale.
8484

85-
The values of current locale has been merged into the root-level.
85+
The properties of current locale has been merged into the root-level properties.
8686

8787
- Example:
8888

docs/zh/reference/client-api.md

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,120 @@
11
# 客户端 API
22

3-
> TODO
3+
客户端 API 是由 [@vuepress/client](https://www.npmjs.com/package/@vuepress/client) Package 提供的,用于开发客户端文件。
4+
5+
## Composition API
6+
7+
### useSiteData
8+
9+
- 详情:
10+
11+
返回站点数据的 Ref 对象。
12+
13+
### useSiteLocaleData
14+
15+
- 详情:
16+
17+
返回当前 locale 的站点数据的 Ref 对象。
18+
19+
当前 locale 中的配置已经合并到顶层配置中。
20+
21+
### useRouteLocale
22+
23+
- 详情:
24+
25+
返回当前路由对应的 locale path 的 Ref 对象。
26+
27+
它的值是 [locales](./config.md#locales) 配置的键之一。
28+
29+
### usePageData
30+
31+
- 详情:
32+
33+
返回当前页面数据的 Ref 对象。
34+
35+
### usePageFrontmatter
36+
37+
- 详情:
38+
39+
返回当前页面 Frontmatter 的 Ref 对象。
40+
41+
它的值是页面数据的 `frontmatter` 属性。
42+
43+
### usePageHead
44+
45+
- 详情:
46+
47+
返回当前页面 Head 配置的 Ref 对象。
48+
49+
它的值是合并 [head](./frontmatter.md#head) Frontmatter 和 [head](./config.md#head) 配置,并进行去重后得到的。
50+
51+
### usePageHeadTitle
52+
53+
- 详情:
54+
55+
返回当前页面 Head 中的标题的 Ref 对象。
56+
57+
它的值是连接页面标题和站点标题后得到的。
58+
59+
### usePageLang
60+
61+
- 详情:
62+
63+
返回当前页面语言的 Ref 对象。
64+
65+
它的值是页面数据的 `lang` 属性。
66+
67+
## 工具函数
68+
69+
### withBase
70+
71+
- 详情:
72+
73+
在 URL 前添加站点 [base](./config.md#base) 前缀。
74+
75+
- 参考:
76+
- [指南 > 静态资源 > Base Helper](../guide/assets.md#base-helper)
77+
78+
## 类型
79+
80+
除了下列提到的类型 Helper 以外,我们同样提供了和上述 Composition API 相关的类型定义,如 `SiteData`, `PageData` 等。
81+
82+
### ClientAppSetup
83+
84+
- 详情:
85+
86+
[clientAppSetupFiles](./plugin-api.md#clientappsetupfiles) 提供的类型 Helper 。
87+
88+
- 示例:
89+
90+
创建 `clientAppSetup.ts` 文件:
91+
92+
```ts
93+
import type { ClientAppSetup } from '@vuepress/client'
94+
95+
const clientAppSetup: ClientAppSetup = () => {
96+
// ...
97+
}
98+
99+
export default clientAppSetup
100+
```
101+
102+
### ClientAppEnhance
103+
104+
- 详情:
105+
106+
[clientAppEnhanceFiles](./plugin-api.md#clientappenhancefiles) 提供的类型 Helper 。
107+
108+
- 示例:
109+
110+
创建 `clientAppEnhance.ts` 文件:
111+
112+
```ts
113+
import type { ClientAppEnhance } from '@vuepress/client'
114+
115+
const clientAppEnhance: ClientAppEnhance = ({ app, router, siteData }) => {
116+
// ...
117+
}
118+
119+
export default clientAppEnhance
120+
```

0 commit comments

Comments
 (0)