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 }, "nav": [ { "text": "首页", "link": "/" }, { "text": "活动推文", "link": "/pages/posts" }, { "text": "关于", "items": [ { "text": "工作室", "link": "/content/about/about-bst" }, { "text": "团队成员", "link": "/pages/team" }, { "text": "加入我们👋", "link": "/content/about/join-us" }, { "text": "赞助信息", "link": "/pages/sponsor" } ] }, { "text": "相关链接", "items": [ { "text": "开发文档", "link": "/content/api-docs/how-to-dev" }, { "text": "AI助手🤖", "link": "/pages/ai" }, { "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/YDvNeYEt0c", "ariaLabel": "qq group link" } ], "editLink": { "text": "在 GitHub 上编辑此页面", "pattern": "https://github.com/JXUT-BST/JXUT-BST.github.io/edit/main/docs/:path" }, "ignoreDeadLinks": "localhostLinks", "search": { "provider": "local", "options": { "locales": { "root": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "displayDetails": "显示详细列表", "resetButtonTitle": "清除查询条件", "backButtonTitle": "关闭搜索", "noResultsText": "无法找到相关结果", "footer": { "selectText": "选择", "selectKeyAriaLabel": "进行选择", "navigateText": "切换", "navigateUpKeyAriaLabel": "向上", "navigateDownKeyAriaLabel": "下降", "closeText": "关闭", "closeKeyAriaLabel": "esc" } } } } } } }, "sidebar": { "content/api-docs/": { "base": "content/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" } ] }, "/content/about/": { "base": "/content/about/", "items": [ { "text": "关于蓝色技术工作室", "link": "about-bst" }, { "text": "团队成员", "link": "bster/index.md", "items": [ { "text": "BST历届负责人", "link": "bster/leader" } ], "collapsed": false }, { "text": "加入我们", "link": "join-us" }, { "text": "Logo 资源", "link": "logo-assets" } ] } }, "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": "content/api-docs/api-examples.md", "filePath": "content/api-docs/api-examples.md", "lastUpdated": 1756983683000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.