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": "/examples/markdown-examples"
},
{
"text": "博客",
"link": "/blogs/csharp-async-aop-trap"
},
{
"text": "游戏",
"link": "/games/minesweeper"
}
],
"sidebar": {
"/examples/": [
{
"text": "示例",
"items": [
{
"text": "Markdown 示例",
"link": "/examples/markdown-examples"
},
{
"text": "Runtime API 示例",
"link": "/examples/api-examples"
},
{
"text": "frontmatter 示例",
"link": "/examples/frontmatter-examples"
}
]
}
],
"/blogs/": [
{
"text": "博客",
"items": [
{
"text": "C# 异步和 AOP 结合时的陷阱",
"link": "/blogs/csharp-async-aop-trap"
}
]
}
],
"/games/": [
{
"text": "休闲游戏",
"collapsed": false,
"items": [
{
"text": "扫雷游戏",
"link": "/games/minesweeper"
}
]
}
]
},
"search": {
"provider": "local",
"options": {
"locales": {
"zh": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"noResultsText": "无法找到相关结果",
"resetButtonTitle": "清除查询条件",
"footer": {
"selectText": "选择",
"navigateText": "切换"
}
}
}
}
}
}
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/brokenstring314/infinitypoint-blog"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "examples/api-examples.md",
"filePath": "examples/api-examples.md",
"lastUpdated": 1760861717000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.