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>Results
Theme Data
{
"outlineTitle": "目录",
"sidebarMenuLabel": "菜单",
"returnToTopLabel": "返回顶部",
"docFooter": {
"prev": "上一篇",
"next": "下一篇"
},
"darkModeSwitchLabel": "切换主题",
"nav": [
{
"text": "主页",
"link": "/"
},
{
"text": "文章",
"link": "/posts/markdown-examples"
}
],
"sidebar": [
{
"text": "文章",
"items": [
{
"text": "Docker 部署 Nginx",
"link": "/posts/Docker-部署-Nginx"
},
{
"text": "CentOS7 安装 Docker 记录学习",
"link": "/posts/CentOS7-安装-Docker-记录学习"
},
{
"text": "Markdown 示例",
"link": "/posts/markdown-examples"
},
{
"text": "运行时 API 示例",
"link": "/posts/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
],
"footer": {
"message": "<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">黔ICP备2025047113号-1</a>",
"copyright": "© 2026 NaoKuo"
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "posts/api-examples.md",
"filePath": "posts/api-examples.md",
"lastUpdated": 0
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.