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": "WordMomo", "sidebar": [ { "text": "帮助文档", "items": [ { "text": "快速开始", "link": "/doc/start-doc.md" }, { "text": "软件下载", "link": "/doc/download" }, { "text": "更新日志", "link": "/doc/update/updateLog.md" } ] }, { "text": "词库管理", "items": [ { "text": "创建空词库", "link": "/doc/wordbook/create-book.md" }, { "text": "更改英式发音", "link": "/doc/wordbook/update-fayin.md" }, { "text": "添加单词", "items": [ { "text": "添加&导入单词", "link": "/doc/wordbook/import-words" }, { "text": "从Excel导入", "link": "/doc/wordbook/import-from-excel.md" }, { "text": "查词工具添加单词", "link": "/doc/wordbook/query-addword.md" }, { "text": "使用AI工具整理导入", "link": "/doc/wordbook/import-from-ai.md" } ] }, { "text": "单元管理", "link": "/doc/wordbook/word-unit.md" }, { "text": "全局熟词管理", "link": "/doc/wordbook/global-word.md" }, { "text": "词汇评分", "link": "/doc/wordbook/wordScore.md" }, { "text": "批量选择", "link": "/doc/wordbook/batch-select.md" } ] }, { "text": "学习工具", "items": [ { "text": "选择单词", "link": "/doc/learntools/select-word.md" }, { "text": "卡片背单词", "link": "/doc/learntools/card-learn-tools.md" }, { "text": "列表快速背单词", "link": "/doc/learntools/list-learn-tools.md" }, { "text": "选题背单词", "link": "/doc/learntools/option-learn-tools.md" }, { "text": "单词拼写练习工具", "link": "/doc/learntools/type-learn-tools.md" }, { "text": "高级拼写工具", "link": "/doc/learntools/super-type-tools.md" } ] }, { "text": "新学与复习", "items": [ { "text": "学习新词", "link": "/doc/learn/learnNewWord.md" }, { "text": "复习单词", "link": "/doc/learn/reviewWord.md" }, { "text": "复习预览", "link": "/doc/learn/reviewPreview.md" }, { "text": "查看次数", "link": "/doc/learn/showCount.md" } ] }, { "text": "扩展资料", "items": [ { "text": "扩展资料介绍", "link": "/doc/reslib/reslib-index.md" }, { "text": "最简译文", "link": "/doc/reslib/update-basicdesc.md" } ] }, { "text": "扩展功能", "items": [ { "text": "桌面弹幕插件", "link": "/doc/extends/barrage-plug.md" }, { "text": "桌面轮播插件", "link": "/doc/extends/switch-plug.md" }, { "text": "桌面贴纸插件", "link": "/doc/extends/sticky-plug.md" }, { "text": "查词翻译插件", "link": "/doc/extends/query-tools.md" } ] }, { "text": "其他功能", "items": [ { "text": "WebDAV同步", "link": "/doc/other/webdav.md" } ] } ], "langMenuLabel": "Language", "returnToTopLabel": "Return to top", "sidebarMenuLabel": "Menu", "darkModeSwitchLabel": "Appearance", "localeLinks": { "text": "Language", "items": [ { "text": "English", "link": "/" }, { "text": "简体中文", "link": "/zh/" }, { "text": "日本语", "link": "/ja/" } ] }, "footer": { "message": "", "copyright": "Copyright © 2025 WordMomo. <a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">粤ICP备20006426号-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.