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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Results
Theme Data
{ "nav": [ { "text": "指南", "link": "/pokemon/guide/", "activeMatch": "^/pokemon/guide/" }, { "text": "缎带", "link": "/pokemon/ribbon/", "activeMatch": "^/pokemon/ribbon/" }, { "text": "乱数", "link": "/pokemon/rng/", "activeMatch": "^/pokemon/rng/" }, { "text": "关于", "activeMatch": "^/archive/", "items": [ { "text": "Markdown", "link": "/archive/markdown", "activeMatch": "^/archive/" }, { "text": "VitePress", "link": "https://vitepress.dev/zh/" }, { "text": "VitePress美化", "link": "https://vitepress.yiov.top/" } ] } ], "sidebar": { "/pokemon/guide/": [ { "text": "Pokémon指南", "collapsed": true, "items": [ { "items": [ { "text": "指南", "link": "/pokemon/guide/" }, { "text": "孵蛋", "link": "/pokemon/guide/other-egg" }, { "text": "闪光锁定", "link": "/pokemon/guide/other-shiny-lock" }, { "text": "Pokémon HOME", "link": "/pokemon/guide/other-home" } ] } ] }, { "text": "第三世代", "collapsed": true, "items": [ { "items": [ { "text": "树果漏洞", "link": "/pokemon/guide/gen3-rtc" }, { "text": "宝可方块漏洞", "link": "/pokemon/guide/gen3-rse-safari-zone" } ] } ] }, { "text": "第九世代", "collapsed": true, "items": [ { "items": [ { "text": "朱紫", "link": "/pokemon/guide/gen9-sv" }, { "text": "传说 Z-A", "link": "/pokemon/guide/gen9-za" } ] } ] } ], "/pokemon/ribbon/": [ { "text": "Pokémon缎带", "collapsed": true, "items": [ { "items": [ { "text": "宝可梦缎带", "link": "/pokemon/ribbon/" }, { "text": "全缎带汇总", "link": "/pokemon/ribbon/other-ribbon-all-gen" }, { "text": "跨世代传送", "link": "/pokemon/ribbon/other-transfer" } ] } ] } ], "/pokemon/rng/": [ { "text": "Pokémon乱数", "collapsed": true, "items": [ { "items": [ { "text": "宝可梦乱数", "link": "/pokemon/rng/" } ] } ] }, { "text": "Gen 8", "collapsed": true, "items": [ { "items": [ { "text": "珍钻复刻", "link": "/pokemon/rng/gen8-bdsp" } ] } ] }, { "text": "Gen 9", "collapsed": true, "items": [ { "items": [ { "text": "朱紫", "link": "/pokemon/rng/gen9-sv" } ] } ] } ], "/console/": [ { "text": "游戏机指南", "collapsed": true, "items": [ { "items": [ { "text": "指南", "link": "/console/" }, { "text": "GB Operator", "link": "/console/gbo" }, { "text": "NGC", "link": "/console/ngc" }, { "text": "DS", "link": "/console/ds" }, { "text": "3DS", "link": "/console/3ds" } ] } ] } ], "/archive/": [ { "text": "Markdown语法", "collapsed": true, "items": [ { "items": [ { "text": "Markdown", "link": "/archive/markdown" }, { "text": "Markdown 扩展", "link": "/archive/md-examples" } ] } ] } ] }, "socialLinks": [ { "icon": { "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" viewBox=\"0 0 16 16\"><path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M7.999 1a.75.75 0 0 1 .715.521L12 11.79l1.286-4.018A.75.75 0 0 1 14 7.25h1.25a.75.75 0 0 1 0 1.5h-.703l-1.833 5.729a.75.75 0 0 1-1.428 0L8.005 4.226l-2.29 7.25a.75.75 0 0 1-1.42.03L3.031 8.03l-.07.208a.75.75 0 0 1-.711.513H.75a.75.75 0 0 1 0-1.5h.96l.578-1.737a.75.75 0 0 1 1.417-.02L4.95 8.919l2.335-7.394A.75.75 0 0 1 7.999 1\" clip-rule=\"evenodd\"/></svg>" }, "link": "https://status.02gamer.top/", "ariaLabel": "站点监测" } ], "algolia": { "appId": "D5KNIQSJBR", "apiKey": "b7ccea04e3de574e4bc754c369469659", "indexName": "Pokemon", "locales": { "root": { "placeholder": "搜索文档", "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "searchBox": { "resetButtonTitle": "清除查询条件", "resetButtonAriaLabel": "清除查询条件", "cancelButtonText": "取消", "cancelButtonAriaLabel": "取消" }, "startScreen": { "recentSearchesTitle": "搜索历史", "noRecentSearchesText": "没有搜索历史", "saveRecentSearchButtonTitle": "保存至搜索历史", "removeRecentSearchButtonTitle": "从搜索历史中移除", "favoriteSearchesTitle": "收藏", "removeFavoriteSearchButtonTitle": "从收藏中移除" }, "errorScreen": { "titleText": "无法获取结果", "helpText": "你可能需要检查你的网络连接" }, "footer": { "selectText": "选择", "navigateText": "切换", "closeText": "关闭", "searchByText": "搜索提供者" }, "noResultsScreen": { "noResultsText": "无法找到相关结果", "suggestedQueryText": "你可以尝试查询", "reportMissingResultsText": "你认为该查询应该有结果?", "reportMissingResultsLinkText": "点击反馈" } } } } } }, "logo": "/logo.svg", "externalLinkIcon": true, "sidebarMenuLabel": "目录", "returnToTopLabel": "返回顶部", "darkModeSwitchLabel": "主题", "lightModeSwitchTitle": "切换到白色模式", "darkModeSwitchTitle": "切换到黑色模式", "outline": { "label": "本页导航", "level": "deep" }, "editLink": { "pattern": "mailto:[email protected]", "text": "问题反馈" }, "lastUpdated": { "text": "最后更新", "formatOptions": { "dateStyle": "short" } }, "docFooter": { "prev": "上一页", "next": "下一页" }, "footer": { "message": "<span id=\"runtime\">本站已运行:<span id=\"A\"> - </span>天<span id=\"B\"> - </span>时<span id=\"C\"> - </span>分<span id=\"D\"> - </span>秒</span>", "copyright": "\n Copyright © 2025 Powered by Gamers\n <span style=\"display:flex; justify-content:center; flex-wrap:wrap; gap:8px; padding-top:8px;\">\n <a target=\"_blank\" href=\"https://vitepress.dev/\" title=\"本站框架基于 VitePress_v1.6.3\">\n <img alt=\"VitePress\" src=\"https://img.shields.io/badge/Frame-VitePress-5672CD?logo=vitepress&logoColor=fff\" />\n </a>\n <a target=\"_blank\" href=\"https://dash.cloudflare.com/\" title=\"本站项目由 Cloudflare 托管\">\n <img alt=\"Cloudflare\" src=\"https://img.shields.io/badge/Server-Cloudflare-F78100?logo=cloudflare&logoColor=fff\" />\n </a>\n <a target=\"_blank\" href=\"https://www.namecheap.com/\" title=\"本站域名管理使用 Namecheap 域名服务\">\n <img alt=\"Namecheap\" src=\"https://img.shields.io/badge/Domain-Namecheap-8A2BE2?logo=namecheap&logoColor=fff\" />\n </a>\n <a target=\"_blank\" href=\"https://umami.is/\" title=\"本站统计服务使用 Umami\">\n <img alt=\"umami\" src=\"https://img.shields.io/badge/Count-Umami-30a46c?logo=umami\" />\n </a>\n </span>\n " } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "archive/md-api-examples.md", "filePath": "archive/md-api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.