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": "/image/base/logo.svg", "nav": [ { "text": "主页", "link": "/" }, { "text": "文档", "link": "/wd/", "activeMatch": "/wd/" } ], "sidebar": { "/demo/": [ { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/demo/markdown-examples" }, { "text": "Runtime API Examples", "link": "/demo/api-examples" } ] } ], "/wd/": [ { "text": "开始", "link": "/wd/" }, { "text": "服务器", "items": [ { "text": "Linux服务器", "link": "/wd/linux" }, { "text": "Runtime API Examples", "link": "/demo/api-examples" } ] } ] }, "search": { "provider": "local", "options": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "displayDetails": "显示详细列表", "footer": { "selectText": "选择", "navigateText": "切换", "closeText": "关闭" } } } } }, "socialLinks": [ { "icon": "github", "link": "https://github.com/xiaolanbai" } ], "footer": { "message": "一只小蓝白 Copyright © 2023", "copyright": "\n <a href=\"http://beian.miit.gov.cn\">鲁ICP备2020045959号-2</a>\n <img src=\"/image/base/jinghui.png\" style=\"display: inline;width: 18px;height: 18px;vertical-align: middle;margin-left: 10px;\" alt=\"示例图片\">\n <a href=\"https://beian.mps.gov.cn/#/query/webSearch?code=37172302372086\">\n 鲁公网安备37172302372086号\n </a>\n " }, "editLink": { "pattern": "https://github.com/xiaolanbai/xiaolanbai.com/blob/main/docs/:path", "text": "在 GitHub 上编辑此页" }, "lastUpdated": { "text": "最后更新于", "formatOptions": { "dateStyle": "medium", "timeStyle": "short" } }, "docFooter": { "prev": "上一篇", "next": "下一篇" }, "darkModeSwitchLabel": "主题模式", "lightModeSwitchTitle": "切换到浅色模式", "darkModeSwitchTitle": "切换到深色模式", "sidebarMenuLabel": "目录", "returnToTopLabel": "返回顶部", "externalLinkIcon": true }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "demo/api-examples.md", "filePath": "demo/api-examples.md", "lastUpdated": 1712768879000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.