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": "首页", "link": "/" }, { "text": "指南", "link": "/vitepress-guide" }, { "text": "示例", "link": "/markdown-examples" } ], "sidebarMenuLabel": "菜单", "outlineTitle": "本页目录", "sidebar": [ { "text": "指南", "collapsed": false, "collapsible": true, "items": [ { "text": "VitePress 指南", "link": "/vitepress-guide" }, { "text": "数学公式", "link": "/math-formulas" }, { "text": "VitePress 部署完整指南", "link": "/vitepress-deployment-guide" }, { "text": "VitePress 在线编辑开发", "link": "/vitepress-online-editing" }, { "text": "Git 命令", "link": "/git-commands" } ] }, { "text": "示例", "collapsed": false, "collapsible": true, "items": [ { "text": "Markdown 示例", "link": "/markdown-examples" }, { "text": "API 示例", "link": "/api-examples" } ] }, { "text": "无人机", "collapsed": false, "collapsible": true, "items": [ { "text": "雷达坐标系转换", "link": "lidar" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/kislate/WebNote" } ] }
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.