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": "/articles/"
},
{
"text": "AI",
"link": "/ai/"
},
{
"text": "专栏",
"items": [
{
"text": "WebRtc",
"link": "/webrtc/guide/"
},
{
"text": "Electron",
"link": "/electron/guide/"
}
]
},
{
"text": "关于作者",
"items": [
{
"text": "FAQ",
"link": "/faq/"
},
{
"text": "Contact",
"link": "/contact/"
}
]
}
],
"sidebar": {
"/articles/": [
{
"text": "文章列表",
"items": [
{
"text": "article1",
"link": "/articles/article1"
},
{
"text": "article2",
"link": "/articles/article2"
}
]
}
],
"/ai/": [
{
"text": "AI文章",
"items": [
{
"text": "aidoc1",
"link": "/ai/aidoc1"
},
{
"text": "aidoc2",
"link": "/ai/aidoc2"
}
]
}
],
"/webrtc/": [
{
"text": "基础",
"collapsible": true,
"items": [
{
"text": "入门",
"link": "/webrtc/guide/"
},
{
"text": "核心概念",
"link": "/webrtc/core-concepts/"
}
]
},
{
"text": "高级",
"collapsible": true,
"items": [
{
"text": "高级用法",
"link": "/webrtc/advanced/"
},
{
"text": "性能优化",
"link": "/webrtc/optimization/"
}
]
}
],
"/electron/": [
{
"text": "Electron 指南",
"items": [
{
"text": "入门",
"link": "/electron/guide/"
},
{
"text": "打包应用",
"link": "/electron/packaging/"
},
{
"text": "调试技巧",
"link": "/electron/debugging/"
}
]
}
]
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/lorilu-studio/"
}
]
}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.