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
{ "outline": [ 2, 6 ], "lightModeSwitchTitle": "切换到浅色模式", "darkModeSwitchTitle": "切换到深色模式", "externalLinkIcon": true, "lastUpdated": { "text": "最后更新时间", "formatOptions": { "dateStyle": "medium", "timeStyle": "short" } }, "editLink": { "pattern": "https://github.com/1411430556/vitepress/edit/main/docs/:path", "text": "在 GitHub 上编辑此页" }, "docFooter": { "prev": "上一页", "next": "下一页" }, "logo": "/logo.png", "nav": [ { "text": "导航", "items": [ { "text": "主页", "link": "/index.md" }, { "text": "情感故事", "link": "/文档/图书馆30秒" }, { "text": "Go初学者", "link": "/文档/Go初学者" }, { "text": "哔哩哔哩", "link": "https://space.bilibili.com/44113085" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/1411430556" }, { "icon": "bilibili", "link": "https://space.bilibili.com/44113085" } ], "footer": { "message": "Released under the MIT License.", "copyright": "Copyright © 2025-present <a target=\"_blank\" href=\"https://github.com/1411430556\">COYG⚡️</a>" }, "search": { "provider": "local", "options": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换", "closeText": "关闭" } } } } }, "sidebar": [ { "items": [ { "text": "文档", "items": [ { "text": "Go初学者", "link": "/文档/Go初学者" }, { "text": "Vue笔记", "link": "/文档/Vue笔记" }, { "text": "Api-Examples", "link": "/文档/api-examples" }, { "text": "Vue3快速上手", "link": "/文档/vue3快速上手" }, { "text": "图书馆30秒", "link": "/文档/图书馆30秒" }, { "text": "示例展示", "link": "/文档/示例展示" } ] } ], "collapsed": false } ] }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "文档/api-examples.md", "filePath": "文档/api-examples.md", "lastUpdated": 1751258449000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.