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.svg", "i18nRouting": true, "socialLinks": [ { "icon": "twitter", "link": "https://x.com/XDevye" } ], "search": { "provider": "local", "options": { "locales": { "zh": { "translations": { "button": { "buttonText": "搜索", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询结果", "footer": { "selectText": "选择", "navigateText": "切换" } } } }, "en": { "translations": { "button": { "buttonText": "Search", "buttonAriaLabel": "Search for Documents" }, "modal": { "noResultsText": "Unable to find relevant results", "resetButtonTitle": "Clear Query Results", "footer": { "selectText": "select", "navigateText": "switch" } } } } } } }, "lastUpdatedText": "Last Updated", "returnToTopLabel": "Back to Top", "docFooter": { "prev": "Previous Page", "next": "Next Page" }, "nav": [ { "text": "Home", "link": "/en/" }, { "text": "User Manual", "link": "/en/user-manual" }, { "text": "Changelog", "link": "/en/version-updates" }, { "text": "Boky", "link": "https://boky.xmagicer.com" } ], "sidebar": [ { "text": "Outline", "items": [ { "text": "User Manual", "link": "/en/user-manual" }, { "text": "Changelog", "link": "/en/version-updates" } ] } ], "outline": { "level": "deep", "label": "Contents" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "en/download.md", "filePath": "en/download.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.