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
{
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "官网",
"link": "https://aiapi.cyou"
}
],
"outline": {
"label": "目录",
"level": "deep"
},
"docFooter": {
"prev": "上一篇",
"next": "下一篇"
},
"darkModeSwitchLabel": "外观",
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式",
"sidebarMenuLabel": "菜单",
"returnToTopLabel": "返回顶部",
"sidebar": [
{
"text": "Examples",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
],
"footer": {
"copyright": "Copyright © 2026 <a href=\"https://aiapi.cyou\" target=\"_blank\">AIAPI.Cyou</a>"
},
"search": {
"provider": "local",
"options": {
"locales": {
"root": {
"translations": {
"button": {
"buttonText": "搜索",
"buttonAriaLabel": "搜索"
},
"modal": {
"displayDetails": "显示详细列表",
"resetButtonTitle": "重置搜索",
"backButtonTitle": "关闭搜索",
"noResultsText": "没有结果",
"footer": {
"selectText": "选择",
"selectKeyAriaLabel": "输入",
"navigateText": "导航",
"navigateUpKeyAriaLabel": "上箭头",
"navigateDownKeyAriaLabel": "下箭头",
"closeText": "关闭",
"closeKeyAriaLabel": "Esc"
}
}
}
}
}
}
},
"lastUpdated": {
"text": "最后更新于",
"formatOptions": {
"dateStyle": "short",
"timeStyle": "short"
}
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1775638737000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.
测试
test