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": "logo.svg", "lastUpdatedText": "最后更新", "search": { "provider": "local", "options": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } } }, "docFooter": { "prev": "上一篇", "next": "下一篇" }, "darkModeSwitchLabel": "外观", "returnToTopLabel": "返回顶部", "sidebarMenuLabel": "菜单", "nav": [ { "text": "后端", "items": [ { "text": "Java基础", "link": "/后端/BasicJava" }, { "text": "Java多线程", "link": "/" }, { "text": "Lambda&Stream", "link": "/" }, { "text": "JavaWeb", "link": "/" }, { "text": "Jdk更新", "link": "/" } ] }, { "text": "前端", "items": [ { "text": "Html", "link": "/" }, { "text": "Css", "link": "/" }, { "text": "JavaScript", "link": "/" }, { "text": "Vue", "link": "/" }, { "text": "Vue-Router", "link": "/" }, { "text": "Vue-x", "link": "/" }, { "text": "Axios", "link": "/" }, { "text": "Echarts", "link": "/" }, { "text": "Element UI", "link": "/" } ] }, { "text": "中间件", "items": [ { "text": "RabbitMQ", "link": "/" }, { "text": "ElasticSearch", "link": "/" }, { "text": "MinIO", "link": "/" }, { "text": "Quartz", "link": "/" }, { "text": "XXL-JOB", "link": "/" }, { "text": "MyBatis", "link": "/" }, { "text": "MyBatis-flex", "link": "/" } ] }, { "text": "Spring", "items": [ { "text": "Spring Framework", "link": "/SpringFramework/Spring" }, { "text": "Spring MvC", "link": "/" }, { "text": "Spring Boot", "link": "/" }, { "text": "SpringCloud Alibaba", "link": "/" }, { "text": "SpringDate JPA", "link": "/" }, { "text": "Spring Security", "link": "/" } ] }, { "text": "408", "items": [ { "text": "计算机组成原理", "link": "/" }, { "text": "计算机网络", "link": "/" }, { "text": "数据结构与算法(Java)", "link": "/" }, { "text": "操作系统", "link": "/" }, { "text": "leetCode", "link": "/" } ] }, { "text": "Linux", "items": [ { "text": "Linux基本操作", "link": "/" }, { "text": "Docker", "link": "/" }, { "text": "Kubernetes", "link": "/" } ] }, { "text": "编程工具", "items": [ { "text": "Git", "link": "/" }, { "text": "Maven", "link": "/" }, { "text": "Gradle", "link": "/" }, { "text": "Nginx", "link": "/" }, { "text": "Hutool", "link": "/" }, { "text": "Apache Commons", "link": "/" }, { "text": "datax", "link": "/" } ] }, { "text": "其他", "link": "/markdown-examples" } ], "sidebar": [ { "text": "后端", "items": [ { "text": "Java", "link": "/后端/BasicJava" } ] }, { "text": "Spring", "items": [ { "text": "Spring Framework", "link": "/SpringFramework/Spring" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/kerwim" }, { "icon": "juejin.png", "link": "https://juejin.cn/user/1975140730538109" } ], "footer": { "copyright": "copyright@ 2024 by kerwim 冀ICP备2024088775号-1" }, "sidebarDepth": 5 }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md", "lastUpdated": null }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.