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.png", "footer": { "message": "<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\" rel=\"noopener noreferrer\"> 辽ICP备19018622号-1 </a><a href=\"https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=21102102000151\" target=\"_blank\" rel=\"noopener noreferrer\"> 辽公网安备 21102102000151号</a>", "copyright": "<a href=\"https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral\" style=\"display:flex;align-items:center;justify-content:center;\"> 本网站由<img src=\"/pic/2024/uplogo.webp\" width=\"59px\" height=\"30px\" />提供cdn加速/云存储服务</a>" } }
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.