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": "Home", "link": "/" }, { "text": "About", "link": "/about/" }, { "text": "Assignments", "link": "/assignments/week1/" }, { "text": "Projects", "link": "/projects/midterm" } ], "sidebar": [ { "text": "Home", "items": [ { "text": "Home page", "link": "/" } ] }, { "text": "About", "items": [ { "text": "About me", "link": "/about/" }, { "text": "Student agreement", "link": "/about/agreement" } ] }, { "text": "Course", "items": [ { "text": "Week 1: Project management", "link": "/assignments/1PM/week1.md" }, { "text": "Week 2: embedded programming", "link": "/assignments/2EP/week2.md" }, { "text": "Week 3: electronics design", "link": "/assignments/3ED/week3.md" }, { "text": "Week 4: CAD", "link": "/assignments/4CAD/week4.md" }, { "text": "Week 5: electronics production", "link": "/assignments/5EP2/week5.md" }, { "text": "Week 6: 3D scanning and printing", "link": "/assignments/6TSP/week6.md" }, { "text": "Week 7: IOT", "link": "/assignments/week7/" }, { "text": "Week 8: \tmid presentation & computer-controlled machining", "link": "/assignments/week8/" }, { "text": "Week 9: Molding and casting", "link": "/assignments/week9/" }, { "text": "Week 10: interface and application programming", "link": "/assignments/week10/" }, { "text": "Week 11: AI&BP", "link": "/assignments/week11/" }, { "text": "Week 12: networking and communications", "link": "/assignments/week12/" }, { "text": "Week 13: vehicle case- parameter design", "link": "/assignments/week13/" }, { "text": "Week 14: computer control cutting", "link": "/assignments/week14/" }, { "text": "Week 15: vehicle case- function test", "link": "/assignments/week15/" }, { "text": "Week 16: vehicle debug", "link": "/assignments/week16/" }, { "text": "Week 17: vehicle debug", "link": "/assignments/week17/" }, { "text": "Week 18: final project test", "link": "/assignments/week18/" }, { "text": "Final project and vehicle case presentation", "link": "/assignments/week19/" } ] }, { "text": "Projects", "items": [ { "text": "Mid-term project", "link": "/projects/midterm" }, { "text": "Final project", "link": "/projects/final" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/vuejs/vitepress" } ] }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.