主题
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", "lang": "zh-CN", "nav": [ { "text": "首页", "link": "/" }, { "text": "前端开发导航", "link": "https://web.codesji.com/" }, { "text": "fontawesome中文文档", "link": "https://fontawesome.codesji.com/" }, { "text": "前端开发博客", "link": "/blog/list" }, { "text": "VitePress", "link": "https://vitejs.cn/vitepress/" } ], "sidebar": { "blog": [ { "text": "前端开发导航", "collapsed": false, "items": [ { "text": "前端开发导航", "link": "https://web.codesji.com/" }, { "text": "ElementUI速查", "link": "/uicomponents/elementui/doc" }, { "text": "Bootstrap中文文档", "link": "/uicomponents/bootstrap/doc" }, { "text": "fontawesome中文文档", "link": "https://fontawesome.codesji" } ] } ], "Examples": [ { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] } ], "/tools/": [ { "text": "常用工具下载", "items": [ { "text": "常用工具下载", "link": "/tools/" }, { "text": "NodeJs", "link": "/tools/nodejs" }, { "text": "Nvm", "link": "/tools/nvm" }, { "text": "Git", "link": "/tools/git" } ] } ], "/config/": [ { "text": "Config", "items": [ { "text": "Index", "link": "/config/" }, { "text": "Three", "link": "/config/three" }, { "text": "Four", "link": "/config/four" } ] } ] }, "lastUpdated": { "text": "最后更新时间", "formatOptions": { "dateStyle": "short", "timeStyle": "medium" } }, "search": { "provider": "local", "options": { "locales": [ "zh-CN", "en-US" ], "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "searchBoxPlaceholder": "搜索文档", "resetButtonTitle": "清除查询条件", "closeButtonAriaLabel": "关闭搜索", "noResultsText": "没有找到结果", "footer": { "selectText": "选择", "noResultsText": "未找到结果", "statsText": { "one": "1个结果", "other": "{n}个结果" }, "closeText": "关闭", "navigateText": "导航到结果" } } } } }, "docFooter": { "prev": "上一页", "next": "下一页" }, "footer": { "message": "Released under the MIT License.", "copyright": "版权所有 Copyright © 2025 | <a href=\"http://beian.miit.gov.cn/\">粤ICP备2024035069号-3</a>" }, "langMenuLabel": "多语言", "returnToTopLabel": "回到顶部", "sidebarMenuLabel": "菜单", "darkModeSwitchLabel": "主题", "lightModeSwitchTitle": "切换到浅色模式", "darkModeSwitchTitle": "切换到深色模式", "outlineTitle": "目录" }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md", "lastUpdated": 1755337878000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.