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
{ "siteTitle": "弈境", "logo": "/logo.png", "logoLink": "/", "nav": [ { "text": "首页", "link": "/" }, { "text": "推荐", "link": "/recommend-article" }, { "text": "博客", "link": "https://blog.tianyichuxin.com" }, { "text": "明宣空间", "link": "https://mingxuan.tech" }, { "text": "公众号", "link": "/wechat" }, { "text": "赞助", "link": "/sponsor" } ], "sidebar": [ { "text": "推荐文章", "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] } ], "outline": { "level": 2, "label": "页面导航" }, "search": { "provider": "local" }, "socialLinks": [ { "icon": "github", "link": "https://gitee.com/tianyichuxin/blog-vue-press/tree/vitepress/" } ], "footer": { "message": "基于 MIT 许可发布", "copyright": "Copyright © 2019-2024 弈心" }, "editLink": { "text": "在 GitHub 上编辑此页面" }, "lastUpdated": { "text": "最后更新于", "formatOptions": { "dateStyle": "short", "timeStyle": "medium" } }, "docFooter": { "prev": "上一页", "next": "下一页" }, "darkModeSwitchLabel": "切换主题", "lightModeSwitchTitle": "切换到亮色主题", "darkModeSwitchTitle": "切换到暗色主题", "externalLinkIcon": true, "returnToTopLabel": "返回顶部" }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md", "lastUpdated": 1727681478000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.