Appearance
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
{ "outlineTitle": "目录", "nav": [ { "text": "Home", "link": "/" }, { "text": "Guide", "items": [ { "text": "Section A Title", "items": [ { "text": "Section A Item A", "link": "..." }, { "text": "Section B Item B", "link": "..." } ] }, { "text": "Section B Title", "items": [ { "text": "Section B Item A", "link": "..." }, { "text": "Section B Item B", "link": "..." } ] } ] }, { "text": "😭", "items": [ { "text": "🤡", "link": "https://www.emojiall.com/zh-hans/emoji/%F0%9F%A4%A1" }, { "text": "🤓", "link": "https://www.emojiall.com/zh-hans/emoji/%F0%9F%A4%93" }, { "text": "😤", "link": "https://www.emojiall.com/zh-hans/emoji/%F0%9F%98%A4" } ] }, { "text": "电子手办", "items": [ { "text": "Cubism 2", "link": "https://klizz.online/z_live2D/indexe.html" }, { "text": "Cubism 3", "link": "https://klizz.online/z_live2D/live2d_3/indexe.html" } ] }, { "text": "About me", "link": "https://klizz111.github.io" } ], "sidebar": [ { "text": "Examples", "items": [ { "text": "远程桌面", "link": "/rdp" }, { "text": "Runtime API Examples", "link": "/api-examples" }, { "text": "zzzz", "link": "/zzz/1.md" } ] }, { "text": "Advanced", "items": [ { "text": "Frontmatter", "link": "/frontmatter" }, { "text": "Global Computed", "link": "/global-computed" }, { "text": "Global Component", "link": "/global-component" }, { "text": "Global Layout", "link": "/global-layout" }, { "text": "Custom Theme", "link": "/custom-theme" }, { "text": "Custom Style", "link": "/custom-style" }, { "text": "Custom Page", "link": "/custom-page" }, { "text": "Custom API", "link": "/custom-api" } ] } ], "search": { "provider": "local", "options": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } } }, "footer": { "copyright": "CopyRight@ 2024 Klizz" }, "editLink": { "pattern": "https://github.com/klizz111/klizz111.github.io/", "text": "Edit this page on GitHub" }, "lastUpdated": { "text": "Updated at", "formatOptions": { "dateStyle": "full", "timeStyle": "short" } } }
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.