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", "outline": { "level": [ 2, 6 ], "label": "文章导航" }, "docFooter": { "prev": "上一篇", "next": "下一篇" }, "sidebarMenuLabel": "目录", "darkModeSwitchLabel": "深浅模式", "lightModeSwitchTitle": "浅色模式", "darkModeSwitchTitle": "深色模式", "returnToTopLabel": "返回顶部", "search": { "provider": "local", "options": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "没有找到结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换", "closeText": "关闭" } } } } }, "footer": { "message": "成烁互动", "copyright": "Copyright © 2024-2025 成烁 All Rights Reserved." }, "lastUpdated": { "text": "最后更新", "formatOptions": { "dateStyle": "medium", "timeStyle": "short" } }, "nav": [ { "text": "主页", "link": "/" }, { "text": "开发文件", "items": [ { "text": "成烁互动开发文件", "link": "/interation" }, { "text": "TOOLKU开发文件", "link": "/toolku" } ] }, { "text": "文件中心", "link": "/markdown-examples" } ], "sidebar": [ { "text": "博客文章", "items": [ { "text": "示例博客", "link": "/api-examples" } ] }, { "text": "更新日志", "items": [ { "text": "示例更新日志", "link": "/markdown-examples" } ] }, { "text": "开发文件", "items": [ { "text": "成烁互动开发文件", "link": "/interation" }, { "text": "TOOLKU开发文件", "link": "/toolku" }, { "text": "成烁的主页v2.0.0源码", "link": "/home2yuanma" } ] }, { "text": "关于", "link": "/up/about" } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/CS-love" } ] }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md", "lastUpdated": 1749211774000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.