Runtime API Examples
This page demonstrates usage of some of the runtime APIs provided by VitePress.
The main useData()
API can be used to access site, theme, and page data for the current page. It works in both .md
and .vue
files:
md
<script setup>
import { useData } from 'vitepress'
const { theme, page, frontmatter } = useData()
</script>
## Results
### Theme Data
<pre>{{ theme }}</pre>
### Page Data
<pre>{{ page }}</pre>
### Page Frontmatter
<pre>{{ frontmatter }}</pre>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Results
Theme Data
{ "logo": "/apple-touch-icon.png", "nav": [ { "text": "前端", "items": [ { "text": "基础", "link": "/frontend/seal和freeze" } ] }, { "text": "算法", "link": "/algorithm/" }, { "text": "归档", "link": "/archive/git" } ], "sidebar": { "/frontend/": { "base": "/frontend/", "items": [ { "text": "seal和freeze", "link": "/seal和freeze" }, { "text": "前端路由", "link": "/前端路由" } ] }, "/archive/": { "base": "/archive/", "items": [ { "text": "Git", "collapsed": false, "items": [ { "text": "Git 配置", "link": "/git" } ] } ] }, "/algorithm/": { "base": "/algorithm/", "items": [ { "text": "LRU", "link": "lru" } ] }, "/net/": { "base": "/net/", "items": [ { "text": "Cors", "link": "cors" }, { "text": "cors的影响范围", "link": "cors的影响范围" } ] } }, "socialLinks": [ { "icon": "github", "link": "https://github.com/starunaway/doxas" } ], "footer": { "message": "Released under the MIT License.", "copyright": "Copyright © 2019-present starunaway" }, "docFooter": { "prev": "上一页", "next": "下一页" }, "externalLinkIcon": true, "search": { "provider": "local" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.