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": "Guide", "activeMatch": "^/guide/", "items": [ { "text": "Guide", "items": [ { "text": "Introduction", "link": "/guide/introduction" }, { "text": "Getting Started", "link": "/guide/getting-started" }, { "text": "Configuration", "link": "/guide/configuration" } ] }, { "text": "Theme", "items": [ { "text": "Extending", "link": "/guide/extending-theme" } ] }, { "text": "Components", "items": [ { "text": "Home", "link": "/guide/home-component" } ] } ] }, { "text": "Examples", "activeMatch": "^/examples/", "items": [ { "text": "Markdown Examples", "link": "/examples/markdown-examples" }, { "text": "Runtime API Examples", "link": "/examples/api-examples" } ] }, { "text": "VitePress", "link": "https://vitepress.dev" } ], "sidebar": [ { "text": "Guide", "items": [ { "text": "Introduction", "link": "/guide/introduction" }, { "text": "Getting Started", "link": "/guide/getting-started" }, { "text": "Configuration", "link": "/guide/configuration" } ] }, { "text": "Theme", "items": [ { "text": "Extending", "link": "/guide/extending-theme" } ] }, { "text": "Components", "items": [ { "text": "Home", "link": "/guide/home-component" } ] }, { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/examples/markdown-examples" }, { "text": "Runtime API Examples", "link": "/examples/api-examples" } ] } ], "outline": [ 2, 3 ], "logo": { "src": "/logo.svg" }, "search": { "provider": "local" }, "editLink": { "pattern": "https://github.com/brenoepics/vitepress-carbon/edit/main/packages/demo/src/:path", "text": "Edit this page on GitHub" }, "lastUpdated": { "formatOptions": { "dateStyle": "short", "timeStyle": "short" } }, "socialLinks": [ { "icon": "github", "link": "https://github.com/brenoepics/vitepress-carbon" } ] }
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": "examples/api-examples.md", "filePath": "examples/api-examples.md", "lastUpdated": 1728239028000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.