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": "/logo.svg",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "全部文档",
"link": "/all"
},
{
"text": "使用指南",
"link": "/guide/",
"activeMatch": "/guide/"
},
{
"text": "学习笔记",
"link": "/notes/",
"activeMatch": "/notes/"
},
{
"text": "示例",
"link": "/examples/",
"activeMatch": "/examples/"
}
],
"sidebar": {
"/guide/": [
{
"text": "使用指南",
"items": [
{
"text": "总览",
"link": "/guide/"
},
{
"text": "快速开始",
"link": "/guide/getting-started"
},
{
"text": "目录结构",
"link": "/guide/structure"
},
{
"text": "写作规范",
"link": "/guide/writing"
}
]
}
],
"/notes/": [
{
"text": "学习笔记",
"items": [
{
"text": "总览",
"link": "/notes/"
},
{
"text": "Markdown 速记",
"link": "/notes/markdown-tips"
},
{
"text": "VitePress 技巧",
"link": "/notes/vitepress-tips"
}
]
}
],
"/examples/": [
{
"text": "示例",
"items": [
{
"text": "总览",
"link": "/examples/"
},
{
"text": "Markdown 语法示例",
"link": "/examples/markdown-examples"
},
{
"text": "运行时 API 示例",
"link": "/examples/api-examples"
}
]
}
]
},
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"displayDetails": "显示详情",
"resetButtonTitle": "清除查询条件",
"backButtonTitle": "返回",
"noResultsText": "没有找到相关结果",
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭"
}
}
}
}
},
"outline": {
"level": [
2,
3
],
"label": "本页目录"
},
"docFooter": {
"prev": "上一篇",
"next": "下一篇"
},
"darkModeSwitchLabel": "外观",
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式",
"sidebarMenuLabel": "目录",
"returnToTopLabel": "回到顶部",
"externalLinkIcon": true,
"footer": {
"message": "基于 VitePress 构建",
"copyright": "© 2026 Citlali Docs"
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/IamXimi"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "examples/api-examples.md",
"filePath": "examples/api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.