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
{ "nav": [ { "text": "首页", "link": "/" }, { "text": "VitePress 文档", "link": "https://vitepress.dev/" } ], "sidebar": [ { "text": "VitePress 示例", "items": [ { "text": "Markdown 示例", "link": "/example/markdown-examples" }, { "text": "API 示例", "link": "/example/api-examples" } ] }, { "text": "Git", "items": [ { "text": "Git 命令", "link": "/git/git-command" }, { "text": "Github", "items": [ { "text": "Github-Pages Deploy", "link": "/git/github/deploy" }, { "text": "External Repository Deploy", "link": "/git/github/external-repository-deploy" } ] } ] }, { "text": "W3c", "items": [ { "text": "国际化", "link": "/w3c/language/i18n" } ] } ], "search": { "provider": "local", "options": { "locales": { "zh": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } } } } }, "editLink": { "pattern": "https://github.com/lin52025i/lin52025-vitepress/tree/master/docs/src/:path", "text": "在 GitHub 上编辑此页面" }, "socialLinks": [ { "icon": "github", "link": "https://github.com/lin52025iq" } ], "footer": { "message": "Released under the MIT License.", "copyright": "Copyright © 2023-present Lin52025" }, "docFooter": { "prev": "上一页", "next": "下一页" }, "lastUpdatedText": "上次更新时间" }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "example/api-examples.md", "lastUpdated": 1683783327000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.