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
{ "nav": [ { "text": "主页", "link": "/" }, { "text": "使用文档", "link": "/doc/start-doc.md" }, { "text": "下载软件", "link": "/doc/download" } ], "logo": "/images/logo.png", "siteTitle": "PixStart", "sidebar": [ { "text": "开始使用", "items": [ { "text": "快速开始", "link": "/doc/start-doc.md" }, { "text": "软件下载", "link": "/doc/download" }, { "text": "更新日志", "link": "/doc/update/updateLog.md" } ] }, { "text": "帮助文档", "items": [ { "text": "将项目移动其他分类", "link": "/doc/other/move.md" }, { "text": "虚拟目录", "link": "/doc/other/virtualFolder.md" }, { "text": "多参数配置", "link": "/doc/other/multParam.md" }, { "text": "更改项目图标", "link": "/doc/other/changIcon.md" }, { "text": "主窗口最大化", "link": "/doc/other/windowMax.md" }, { "text": "更改数据存储路径", "link": "/doc/other/updateDataPath.md" } ] }, { "text": "Pix脚本", "items": [ { "text": "Pix脚本介绍", "link": "/doc/script/script.md" }, { "text": "常用命令", "link": "/doc/script/cmd.md" } ] }, { "text": "常见问题", "items": [ { "text": "下载被拦截", "link": "/doc/safe/lanjie.md" } ] } ], "returnToTopLabel": "Return to top", "sidebarMenuLabel": "Menu", "darkModeSwitchLabel": "Appearance", "footer": { "message": "", "copyright": "Copyright © 2025 PixStart. <a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">皖ICP备19013259号-4</a>" }, "detectBrowserLanguage": { "enable": true, "redirectWhenCookieNotSet": true } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.