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": "/lixunchang.png", "nav": [ { "text": "首页", "link": "/" }, { "text": "技术", "activeMatch": "/list/tech/", "link": "/list/tech" }, { "text": "生活", "activeMatch": "/list/survive/", "link": "/list/survive" }, { "text": "思想", "activeMatch": "/list/thought/", "link": "/list/thought" }, { "text": "简介", "activeMatch": "/intro/", "link": "/intro" } ], "sidebar": { "/intro/": [ { "text": "简介", "link": "/intro" }, { "text": "开源项目", "link": "/intro/open-source" }, { "text": "个人简历", "link": "/intro/resume" }, { "text": "汇编年", "link": "/intro/history" } ] }, "aside": true, "outline": { "level": [ 2, 6 ], "label": "大纲" }, "socialLinks": [ { "icon": "github", "link": "https://github.com/lixunchang" } ], "footer": { "message": "十年专业,品质保障", "copyright": "版权所有 © 2024-2029 八阿哥修理铺" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "tech/api-examples.md", "filePath": "tech/api-examples.md", "lastUpdated": 1728579357000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.