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
{ "sidebar": { "/gaokao": [ { "text": "高考", "items": [ { "text": "2017 全国 I 卷理数", "link": "/gaokao/2017-national1-math/" }, { "text": "2018 全国 I 卷理数答案", "link": "/gaokao/2018-national1-math-answers" }, { "text": "2019 全国 I 卷理数答案", "link": "/gaokao/2019-national1-math-answers" }, { "text": "2020 全国 I 卷理数", "link": "/gaokao/2020-national1-math/" }, { "text": "2021 新高考 I 卷数学", "link": "/gaokao/2021-xgk1-math/" } ] } ] }, "outline": [ 2, 3 ], "search": { "provider": "local" }, "socialLinks": [ { "icon": "github", "link": "https://github.com/1024th" } ], "giscus": { "repo": "1024th/blog-giscus", "repoId": "R_kgDOL7seBQ", "category": "Announcements", "categoryId": "DIC_kwDOL7seBc4CfXiz" }, "nav": [ { "text": "Home", "link": "/" }, { "text": "CV", "link": "/cv" }, { "text": "Posts", "link": "/posts" }, { "text": "Tags", "link": "/tags" } ] }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "title": "Runtime API Examples", "date": "2023-01-01T00:00:00.000Z", "outline": "deep", "sidebar": false, "prev": false, "next": false, "isPost": true }, "headers": [], "relativePath": "posts/api-examples.md", "filePath": "posts/api-examples.md" }
Page Frontmatter
{ "title": "Runtime API Examples", "date": "2023-01-01T00:00:00.000Z", "outline": "deep", "sidebar": false, "prev": false, "next": false, "isPost": true }
More
Check out the documentation for the full list of runtime APIs.