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
{ "logo": "/logo.svg", "editLink": { "pattern": "https://github.com/YJLAugus/VitePresslab/edit/main/docs/:path", "text": "Edit this page on GitHub" }, "search": { "provider": "local" }, "nav": [ { "text": "主页", "link": "/" }, { "text": "新闻", "link": "/markdown-examples" }, { "text": "实验室", "items": [ { "text": "成果", "link": "/markdown-examples" }, { "text": "组员介绍", "link": "/team" }, { "text": "组内活动", "link": "/markdown-examples" } ] } ], "sidebar": [ { "text": "关于实验室", "collapsed": false, "items": [ { "text": "关于", "link": "/about" }, { "text": "研究方向", "link": "/research" } ] }, { "text": "最新消息", "collapsed": false, "items": [ { "text": "竞赛获奖🥇", "link": "/awards" }, { "text": "大事件⚡️", "link": "/news" } ] }, { "text": "组内活动", "collapsed": false, "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] }, { "text": "组员介绍", "collapsed": false, "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] } ], "footer": { "message": "Released under the MIT License.", "copyright": "Copyright © 2025 深度编程实验室(DeepCodeLab)" }, "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", "lastUpdated": 1750324667000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.