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": "/favicon.ico", "siteTitle": false, "search": { "provider": "local", "options": { "locales": { "root": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "displayDetails": "显示详细列表", "resetButtonTitle": "清除查询条件", "backButtonTitle": "关闭搜索", "noResultsText": "无法找到相关结果", "footer": { "selectText": "选择", "selectKeyAriaLabel": "进行选择", "navigateText": "切换", "navigateUpKeyAriaLabel": "向上", "navigateDownKeyAriaLabel": "下降", "closeText": "关闭", "closeKeyAriaLabel": "esc" } } } }, "en": { "translations": { "button": { "buttonText": "Search", "buttonAriaLabel": "Search" }, "modal": { "displayDetails": "Display detailed list", "resetButtonTitle": "Reset search", "backButtonTitle": "Close search", "noResultsText": "No results for", "footer": { "selectText": "to select", "selectKeyAriaLabel": "enter", "navigateText": "to navigate", "navigateUpKeyAriaLabel": "up arrow", "navigateDownKeyAriaLabel": "down arrow", "closeText": "to close", "closeKeyAriaLabel": "escape" } } } } } } }, "nav": [ { "text": "Websites", "items": [ { "text": "Atomeocean", "link": "https://atomeocean.com" }, { "text": "Cruise", "link": "https://cruise.atomeocean.com" } ] } ], "lastUpdated": { "text": "Last updated" }, "footer": { "message": "Atomeocean Open Source Mapstruct", "copyright": "Copyright © 2021-present Atomeocean" }, "sidebar": { "/": { "base": "/", "items": [ { "text": "Get-started", "items": [ { "text": "快速入门MapStruct (2分钟)", "link": "get-started/map-struct-in-2-minutes" } ], "collapsed": false }, { "text": "MapStruct 介绍", "link": "mapstruct-introduction" }, { "text": "Project_setup_info", "link": "project_setup_info" }, { "text": "视频广告", "items": [ { "text": "H1b真香", "link": "video-ads/h1b-really-nice" }, { "text": "二手物品广告", "link": "video-ads/preowned-item" }, { "text": "NJ公寓看房视频", "link": "video-ads/room-tour-in-nj" } ], "collapsed": false } ] }, "/en/": { "base": "/en/", "items": [ { "text": "Runtime API Examples", "link": "api-examples" }, { "text": "English Content", "link": "dummy" }, { "text": "Introduction", "link": "mapstruct-introduction" }, { "text": "Markdown Extension Examples", "link": "markdown-examples" } ] } }, "socialLinks": [ { "icon": "github", "link": "https://github.com/atomeocean/atomeocean-cn-mapstruct" }, { "icon": "youtube", "link": "https://www.youtube.com/@atomeocean" }, { "icon": "linkedin", "link": "https://www.linkedin.com/company/atomeocean" } ], "editLink": { "text": "Edit this page" }, "docFooter": { "prev": "Previous page", "next": "Next page" }, "outline": { "label": "On this page" }, "langMenuLabel": "Change language", "returnToTopLabel": "Return to top", "sidebarMenuLabel": "Menu", "darkModeSwitchLabel": "Appearance", "lightModeSwitchTitle": "Switch to light theme", "darkModeSwitchTitle": "Switch to dark theme" }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "en/api-examples.md", "filePath": "en/api-examples.md", "lastUpdated": 1732214242000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.