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": "/"
}
],
"sidebar": [
{
"text": "Examples",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": {
"svg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><svg style=\"transform: scale(1.75); background: #fff; border-radius: 100vmax;\" id=\"_レイヤー_1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 493 493\"><defs><style>.cls-1{fill:#040000;}</style></defs><path class=\"cls-1\" d=\"m139.57,142.06c41.19,0,97.6-2.09,138.1-1.04,54.34,1.39,74.76,25.06,75.45,83.53.69,33.06,0,127.73,0,127.73h-58.79c0-82.83.35-96.5,0-122.6-.69-22.97-7.25-33.92-24.9-36.01-18.69-2.09-71.07-.35-71.07-.35v158.96h-58.79v-210.22Z\"/></svg>"
},
"link": "https://note.com/yuyuworks"
},
{
"icon": {
"svg": "<svg style=\"transform: scale(0.925);\" xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584l-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z\"/></svg>"
},
"link": "https://x.com/catshogistudio"
}
],
"footer": {
"copyright": "© 2025 YUYU"
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep",
"head": [
[
"meta",
{
"name": "robots",
"content": "noindex"
}
]
]
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md"
}Page Frontmatter
{
"outline": "deep",
"head": [
[
"meta",
{
"name": "robots",
"content": "noindex"
}
]
]
}More
Check out the documentation for the full list of runtime APIs.