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": "/logo.png", "search": { "provider": "local" }, "socialLinks": [ { "icon": "github", "link": "https://github.com/vuejs/vitepress" } ], "nav": [ { "text": "home", "link": "/en/" }, { "text": "finance", "link": "/en/finance/how-much-money-do-you-need-to-be-in-the-top-1-percent" }, { "text": "electronics", "link": "/en/electronics/global-smartphone-market-share-counterpoint-2024" }, { "text": "examples", "link": "/en/markdown-examples" }, { "text": "test", "items": [ { "text": "test1", "link": "/en/test/test1" } ] } ], "sidebar": { "/en/markdown-examples": { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/en/markdown-examples" }, { "text": "Runtime API Examples", "link": "/en/api-examples" } ] }, "/en/electronics/": { "text": "消费电子榜单", "items": [ { "text": "全球手机市场", "link": "/en/electronics/global-smartphone-market-share-counterpoint-2024" }, { "text": "中国时间市场", "link": "/en/electronics/china-smartphone-market-share-counterpoint-2024" }, { "text": "测试4", "link": "/en/WealthThresholdChart" } ] }, "/en/test/": { "text": "测试侧边栏", "items": [ { "text": "测试1", "link": "/en/test/test1" }, { "text": "测试2", "link": "/en/test/test2" }, { "text": "测试3", "link": "/en/Charts" }, { "text": "测试5", "link": "/en/how-much-money-do-you-need-to-be-in-the-top-1-percent" }, { "text": "测试4", "link": "/en/WealthThresholdChart" } ] } } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "en/api-examples.md", "filePath": "en/api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.