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": "Home",
"link": "/"
},
{
"text": "Personal",
"link": "/personal/"
},
{
"text": "Topsfuture",
"link": "/topsfuture/"
},
{
"text": "Debug",
"link": "/debug/"
}
],
"sidebar": {
"/personal/": [
{
"text": "Personal",
"items": [
{
"text": "Personal 首页",
"link": "/personal/"
}
]
}
],
"/topsfuture/": [
{
"text": "Topsfuture",
"items": [
{
"text": "Topsfuture 首页",
"link": "/topsfuture/"
},
{
"text": "rpi-imager / tps-imager 构建指南",
"link": "/topsfuture/rpi-imager-build-guide"
},
{
"text": "Git 提交与 MR 流程",
"link": "/topsfuture/Git-MergeRequest"
}
]
}
],
"/debug/": [
{
"text": "Debug",
"items": [
{
"text": "Debug 首页",
"link": "/debug/"
},
{
"text": "博客操作手册",
"link": "/debug/blog-manual"
},
{
"text": "Markdown Examples",
"link": "/debug/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/debug/api-examples"
}
]
}
]
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "debug/api-examples.md",
"filePath": "debug/api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.