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": "上次更新", "returnToTopLabel": "返回顶部", "docFooter": { "prev": "上一页", "next": "下一页" }, "nav": [ { "text": "主页", "link": "/zh/" }, { "text": "使用手册", "link": "/zh/user-manual" }, { "text": "更新日志", "link": "/zh/version-updates" }, { "text": "Boky", "link": "https://boky.xmagicer.com" } ], "sidebar": [ { "text": "大纲", "items": [ { "text": "使用手册", "link": "/zh/user-manual" }, { "text": "更新日志", "link": "/zh/version-updates" } ] } ], "outline": { "level": "deep", "label": "目录" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "zh/download.md", "filePath": "zh/download.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.