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>
<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.png", "lastUpdated": { "formatOptions": { "forceLocale": true } }, "search": { "provider": "local", "options": { "detailedView": true } }, "nav": [ { "text": "Home", "link": "/" }, { "text": "Wiki", "link": "/wiki/" }, { "text": "v1.1.0", "items": [ { "text": "About Me", "link": "/wiki/about-me.md" } ] } ], "sidebar": [ { "text": "🏠 Home", "link": "/wiki/" }, { "text": "📝 Blog", "docFooterText": "Blog", "collapsed": true, "items": [ { "text": "2024", "link": "/wiki/blog/2024/", "items": [ { "text": "📣 Mediator vs Observer", "link": "/wiki/blog/2024/mar/mediator-vs-observer-classroom" }, { "text": "📱 Expo Social Login", "link": "/wiki/blog/2024/expo-social-login/", "collapsed": true, "items": [ { "text": "Google Sign In 🤖", "link": "/wiki/blog/2024/expo-social-login/expo-google-sign-in" }, { "text": "Apple Sign In 🍎", "link": "/wiki/blog/2024/expo-social-login/expo-apple-sign-in" }, { "text": "Supabase Auth Setup ⚡️", "link": "/wiki/blog/2024/expo-social-login/expo-supabase-setup" } ] } ] } ] }, { "text": "🤖 Data Structures & Algorithms", "link": "/wiki/dsa/", "docFooterText": "Data Structures & Algorithms", "collapsed": true, "items": [ { "text": "Trie", "link": "/wiki/dsa/trie/" }, { "text": "Binary Search Tree", "link": "/wiki/dsa/binary-search-tree/" } ] }, { "text": "👨💻 Programming Languages", "collapsed": true, "docFooterText": "Programming Languages", "link": "/wiki/programming-languages/", "items": [ { "text": "🐿️ Go", "link": "/wiki/programming-languages/go/" }, { "text": "☕️ Java", "link": "/wiki/programming-languages/java/" } ] }, { "text": "🎨 Design Patterns", "collapsed": true, "docFooterText": "Design Patterns", "link": "/wiki/design-patterns/", "items": [ { "text": "Creational", "link": "/wiki/design-patterns/creational/" }, { "text": "Structural", "link": "/wiki/design-patterns/structural/" }, { "text": "Behavioral", "link": "/wiki/design-patterns/behavioral/", "items": [ { "text": "Observer", "link": "/wiki/design-patterns/behavioral/observer" }, { "text": "Mediator", "link": "/wiki/design-patterns/behavioral/mediator" } ] } ] }, { "text": "🌐 System Design", "collapsed": true, "docFooterText": "System Design", "link": "/wiki/system-design/", "items": [] }, { "text": "🏗️ Domain Driven Design", "collapsed": true, "docFooterText": "Domain Driven Design", "link": "/wiki/ddd/", "items": [ { "text": "🤖 Discussions with Chat GPT", "collapsed": true, "link": "/wiki/ddd/chat-gpt/", "items": [ { "text": "Sub-domains vs Bounded Context", "link": "/wiki/ddd/chat-gpt/subdomain-bounded-context" }, { "text": "Aggregates Transaction Boundaries", "link": "/wiki/ddd/chat-gpt/aggregates-transaction-boundaries" }, { "text": "SaaS products and core domains not in-house", "link": "/wiki/ddd/chat-gpt/ddd-saas-products" } ] } ] }, { "text": "📒 Vitepress Examples", "collapsed": true, "docFooterText": "Vitepress Examples", "items": [ { "text": "Markdown Examples", "link": "/wiki/vite-examples/markdown-examples" }, { "text": "Runtime API Examples", "link": "/wiki/vite-examples/api-examples" } ] }, { "text": "🙋 About Me", "link": "/wiki/about-me.md" } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/giovannymassuia/wiki.giovannymassuia.io" } ], "footer": { "message": "Giovanny Massuia 👨💻", "copyright": "Copyright © 2023" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "wiki/vite-examples/api-examples.md", "filePath": "wiki/vite-examples/api-examples.md", "lastUpdated": 1703088882000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.