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
{
"logo": "/web_logo.png",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "指南",
"items": [
{
"text": "A",
"link": "/"
},
{
"text": "B",
"link": "/"
},
{
"text": "C",
"link": "/"
}
]
},
{
"text": "软件开发",
"link": "/"
},
{
"text": "学习笔记",
"link": "/"
},
{
"text": "阅读笔记",
"link": "/"
},
{
"text": "语言学习",
"link": "/"
},
{
"text": "",
"link": "https://vitepress.dev/zh/"
}
],
"sidebar": [
{
"text": "指南",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/xuchenxu2004"
},
{
"icon": "x",
"link": "https://x.com/XCX_SZSZ"
}
],
"search": {
"provider": "local"
},
"lastUpdated": {
"text": "最后更新于",
"formatOptions": {
"dateStyle": "short",
"timeStyle": "medium"
}
},
"editLink": {
"pattern": "https://github.com/xuchenxu2004/xuchenxuBlog.git",
"text": "在GitHub编辑本页"
},
"footer": {
"message": "Released under the MIT License.",
"copyright": "Copyright © 2026-2030 present xuchenxu2004"
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1769704731000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.
