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
{ "logo": { "src": "/bst-logo.svg", "width": 24, "height": 24 }, "search": { "provider": "local", "options": { "locales": { "root": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "displayDetails": "显示详细列表", "resetButtonTitle": "清除查询条件", "backButtonTitle": "关闭搜索", "noResultsText": "无法找到相关结果", "footer": { "selectText": "选择", "selectKeyAriaLabel": "进行选择", "navigateText": "切换", "navigateUpKeyAriaLabel": "向上", "navigateDownKeyAriaLabel": "下降", "closeText": "关闭", "closeKeyAriaLabel": "esc" } } } } } } }, "nav": [ { "text": "首页", "link": "/" }, { "text": "活动推文", "link": "/posts" }, { "text": "关于我们", "items": [ { "text": "工作室", "link": "/about/about-bst" }, { "text": "团队成员", "link": "/team" } ] }, { "text": "加入我们", "link": "/contact/join-us" }, { "text": "知识库", "link": "https://eab6f7z1wy1.feishu.cn/wiki/NOW6w8DUriguJskA5p0cKUjenmc?from=from_copylink" } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/JXUT-BST" }, { "icon": { "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\">\n\t<path fill=\"currentColor\" d=\"M21.395 15.035a40 40 0 0 0-.803-2.264l-1.079-2.695c.001-.032.014-.562.014-.836C19.526 4.632 17.351 0 12 0S4.474 4.632 4.474 9.241c0 .274.013.804.014.836l-1.08 2.695a39 39 0 0 0-.802 2.264c-1.021 3.283-.69 4.643-.438 4.673c.54.065 2.103-2.472 2.103-2.472c0 1.469.756 3.387 2.394 4.771c-.612.188-1.363.479-1.845.835c-.434.32-.379.646-.301.778c.343.578 5.883.369 7.482.189c1.6.18 7.14.389 7.483-.189c.078-.132.132-.458-.301-.778c-.483-.356-1.233-.646-1.846-.836c1.637-1.384 2.393-3.302 2.393-4.771c0 0 1.563 2.537 2.103 2.472c.251-.03.581-1.39-.438-4.673\" />\n</svg>" }, "link": "https://qm.qq.com/q/HvMQU9y5a0", "ariaLabel": "qq group link" } ], "editLink": { "text": "在 GitHub 上编辑此页面", "pattern": "https://github.com/JXUT-BST/JXUT-BST.github.io/edit/main/docs/:path" }, "sidebar": { "/api-docs/": { "base": "/api-docs/", "items": [ { "text": "开发文档", "link": "how-to-dev" }, { "text": "Runtime API Examples", "link": "api-examples" }, { "text": "Markdown Extension Examples", "link": "markdown-examples" }, { "text": "VitePress Plugin Docs", "link": "vitepress-plugin" } ] }, "/about/": { "base": "/about/", "items": [ { "text": "关于蓝色技术工作室", "link": "about-bst" }, { "text": "团队成员", "link": "bster/index.md", "items": [ { "text": "人物志", "link": "bster/hero/index.md", "items": [ { "text": "2013", "items": [ { "text": "徐昌坤", "link": "bster/hero/2013/徐昌坤/index.md" }, { "text": "汪隆", "link": "bster/hero/2013/汪隆/index.md" } ], "collapsed": true }, { "text": "2014", "items": [ { "text": "刘玉彪", "link": "bster/hero/2014/刘玉彪/index.md" }, { "text": "杨骏新", "link": "bster/hero/2014/杨骏新/index.md" }, { "text": "石集权", "link": "bster/hero/2014/石集权/index.md" }, { "text": "魏来", "link": "bster/hero/2014/魏来/index.md", "items": [ { "text": "创新之星发言稿", "link": "bster/hero/2014/魏来/2016年创新之星发言稿/index.md" }, { "text": "2016年度全省五四红旗团支部事迹材料", "link": "bster/hero/2014/魏来/2016年度全省五四红旗团支部事迹材料/index.md" }, { "text": "活力团支部申请书", "link": "bster/hero/2014/魏来/2016年活力团支部申请书/index.md" }, { "text": "任职负责人发言稿", "link": "bster/hero/2014/魏来/任职负责人发言稿/index.md" } ], "collapsed": true } ], "collapsed": true } ], "collapsed": false }, { "text": "负责人", "link": "bster/leader/index.md", "items": [ { "text": "BST历届负责人", "link": "bster/leader/leader" } ], "collapsed": false } ], "collapsed": false } ] } }, "docFooter": { "prev": "上一页", "next": "下一页" }, "outline": { "label": "页面导航" }, "lastUpdated": { "text": "最后更新于" }, "langMenuLabel": "多语言", "returnToTopLabel": "回到顶部", "sidebarMenuLabel": "菜单", "darkModeSwitchLabel": "主题", "lightModeSwitchTitle": "切换到浅色模式", "darkModeSwitchTitle": "切换到深色模式" }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-docs/api-examples.md", "filePath": "api-docs/api-examples.md", "lastUpdated": 1729329637000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.