Runtime API Examples
作者: 更新: 3/5/2025 字数: 0 字 时长: 0 分钟
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": "/favicon.ico", "darkModeSwitchLabel": "深浅模式", "sidebarMenuLabel": "目录", "returnToTopLabel": "返回顶部", "search": { "provider": "algolia", "options": { "appId": "IQL7R3ODWD", "apiKey": "beb5404457e245cc1397d34625586ac4", "indexName": "xinfei", "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": "点击反馈" } } } } } } }, "nav": [ { "text": "🏠 主页", "link": "/" }, { "text": "编程学习", "items": [ { "text": "基础巩固", "link": "/blog/basic/index" }, { "text": "进阶学习", "link": "/blog/advanced/index" }, { "text": "强化拓展", "link": "/blog/enhancement/index" } ] }, { "text": "每日一题", "link": "/daily/浏览器精确计时问题" }, { "text": "随笔录", "link": "/other/api-examples" } ], "sidebar": { "/blog/basic/": { "base": "/blog/basic/", "items": [ { "text": "基础巩固", "items": [ { "text": "浏览器渲染原理01", "link": "浏览器渲染原理01" }, { "text": "浏览器渲染原理02", "link": "浏览器渲染原理02" }, { "text": "浏览器渲染原理03", "link": "浏览器渲染原理03" }, { "text": "JavaScript执行原理01", "link": "JavaScript执行原理01" }, { "text": "JavaScript执行原理02", "link": "JavaScript执行原理02" }, { "text": "JavaScript知识整理", "link": "JavaScript知识整理" }, { "text": "你不知道的Hashbang注释", "link": "你不知道的Hashbang注释" }, { "text": "立即执行函数表达式-IIFE", "link": "立即执行函数表达式-IIFE" } ] } ] }, "/blog/advanced/": { "base": "/blog/advanced/", "items": [ { "text": "进阶学习", "items": [] } ] }, "/blog/enhancement/": { "base": "/blog/enhancement/", "items": [ { "text": "强化拓展", "items": [] } ] }, "/other/": { "base": "/other/", "items": [ { "text": "随想录", "items": [ { "text": "api-examples", "link": "api-examples" }, { "text": "markdown-examples", "link": "markdown-examples" } ] } ] }, "/daily/": { "base": "/daily/", "items": [ { "text": "每日一题", "items": [ { "text": "defer和async的作用", "link": "defer和async的作用" }, { "text": "浏览器精确计时问题", "link": "浏览器精确计时问题" } ] } ] }, "/category/csstrick/": { "base": "/category/csstrick/", "items": [ { "text": "CSS 揭秘", "items": [ { "text": "歌词跟随歌曲播放效果", "link": "歌词跟随歌曲播放效果" } ] } ] }, "/category/algorithm/": { "base": "/category/algorithm/", "items": [ { "text": "算法专栏", "items": [ { "text": "英文输入法", "link": "英文输入法" } ] } ] } }, "socialLinks": [ { "icon": { "svg": "<svg t=\"1703483542872\" class=\"icon\" viewBox=\"0 0 1309 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"6274\" width=\"200\" height=\"200\"><path d=\"M1147.26896 912.681417l34.90165 111.318583-127.165111-66.823891a604.787313 604.787313 0 0 1-139.082747 22.263717c-220.607239 0-394.296969-144.615936-394.296969-322.758409s173.526026-322.889372 394.296969-322.889372C1124.219465 333.661082 1309.630388 478.669907 1309.630388 656.550454c0 100.284947-69.344929 189.143369-162.361428 256.130963zM788.070086 511.869037a49.11114 49.11114 0 0 0-46.360916 44.494692 48.783732 48.783732 0 0 0 46.360916 44.494693 52.090549 52.090549 0 0 0 57.983885-44.494693 52.385216 52.385216 0 0 0-57.983885-44.494692z m254.985036 0a48.881954 48.881954 0 0 0-46.09899 44.494692 48.620028 48.620028 0 0 0 46.09899 44.494693 52.385216 52.385216 0 0 0 57.983886-44.494693 52.58166 52.58166 0 0 0-57.951145-44.494692z m-550.568615 150.018161a318.567592 318.567592 0 0 0 14.307712 93.212943c-14.307712 1.080445-28.746387 1.768001-43.283284 1.768001a827.293516 827.293516 0 0 1-162.394168-22.296458l-162.001279 77.955749 46.328175-133.811485C69.410411 600.858422 0 500.507993 0 378.38496 0 166.683208 208.689602 0 463.510935 0c227.908428 0 427.594322 133.18941 467.701752 312.379588a427.463358 427.463358 0 0 0-44.625655-2.619261c-220.24709 0-394.100524 157.74498-394.100525 352.126871zM312.90344 189.143369a64.270111 64.270111 0 0 0-69.803299 55.659291 64.532037 64.532037 0 0 0 69.803299 55.659292 53.694846 53.694846 0 0 0 57.852923-55.659292 53.465661 53.465661 0 0 0-57.852923-55.659291z m324.428188 0a64.040926 64.040926 0 0 0-69.574114 55.659291 64.302852 64.302852 0 0 0 69.574114 55.659292 53.694846 53.694846 0 0 0 57.951145-55.659292 53.465661 53.465661 0 0 0-57.951145-55.659291z\" p-id=\"6275\"></path></svg>" }, "link": "https://www.xinfei.fun/wx/index.html", "ariaLabel": "wechat" }, { "icon": "github", "link": "https://github.com/xinfei-fun/YouZi_Stack" } ], "footer": { "message": "<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">鄂ICP备2025094437号-1</a>", "copyright": "Copyright © 2025-present Baker Kong" }, "outline": { "level": "deep", "label": "当前页大纲" }, "lastUpdated": { "text": "更新于", "formatOptions": { "dateStyle": "full", "timeStyle": "medium" } }, "editLink": { "pattern": "https://github.com/xinfei-fun/YouZi_Stack/edit/main/src/:path", "text": "在GitHub编辑本页" }, "docFooter": { "prev": "上一篇", "next": "下一篇" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "other/api-examples.md", "filePath": "other/api-examples.md", "lastUpdated": 1741163301000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.