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": "ドキュメント", "activeMatch": "^/tutorial/", "items": [ { "text": "チュートリアル", "items": [ { "text": "API", "link": "/tutorial/api-examples" }, { "text": "Markdown", "link": "/tutorial/markdown-examples" } ] } ] }, { "text": "サイト", "activeMatch": "^/site/", "items": [ { "text": "K Web Storage", "link": "https://k-web-storage.lab.kuwanomi0.com/" } ] } ], "sidebar": { "/tutorial/": [ { "text": "API", "items": [ { "text": "Runtime API Example", "link": "/tutorial/api-examples" }, { "text": "Markdown Extension Examples", "link": "/tutorial/markdown-examples" } ] } ] }, "localeLinks": [], "socialLinks": [ { "icon": "twitter", "link": "https://twitter.com/kuwanomi0" } ] }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [ { "level": 2, "title": "Results", "slug": "results", "link": "#results", "children": [ { "level": 3, "title": "Theme Data", "slug": "theme-data", "link": "#theme-data", "children": [] }, { "level": 3, "title": "Page Data", "slug": "page-data", "link": "#page-data", "children": [] }, { "level": 3, "title": "Page Frontmatter", "slug": "page-frontmatter", "link": "#page-frontmatter", "children": [] } ] }, { "level": 2, "title": "More", "slug": "more", "link": "#more", "children": [] } ], "relativePath": "tutorial/api-examples.md", "filePath": "tutorial/api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.