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
{ "footer": { "message": "<img src='/images/police.png' style='width: 16px;height: 16px;display: inline-block;vertical-align: middle;' alt='China'/><a href='https://beian.mps.gov.cn/#/query/webSearch?code=42011102005514' rel='noreferrer' target='_blank'> 鄂公网安备42011102005514</a> <a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">鄂ICP备2024076957号-1</a>", "copyright": "Copyright © 2024 <img src=\"/images/license.png\" alt=\"\" style='width: 16px;height: 16px;display: inline-block;vertical-align: middle;'/> CC-BY-4.0 license" }, "nav": [ { "text": "首页", "link": "/" }, { "text": "独立文章", "link": "/article/" }, { "text": "Examples", "link": "/markdown-examples" } ], "sidebar": { "/": [ { "text": " asd222", "items": [ { "text": "1111", "link": "/markdown-examples" }, { "text": "2222", "link": "/api-examples" } ] } ], "/article/HTML/": [ { "text": "HTML", "items": [ { "text": "啊实打实", "link": "/markdown-examples" }, { "text": "啊萨达", "link": "/api-examples" } ] }, { "text": "HTML2", "items": [ { "text": " 萨达", "link": "/markdown-examples" }, { "text": "啊萨达", "link": "/api-examples" } ] } ] }, "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.