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": "Home",
"link": "/"
},
{
"text": "VitePress Help",
"link": "/category1/index"
},
{
"text": "知识积累",
"link": "/category2/index"
}
],
"sidebar": {
"/category1/": [
{
"text": "VitePress Help",
"link": "/category1/index",
"items": [
{
"text": "Markdown Examples",
"link": "/category1/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/category1/api-examples"
}
],
"collapsed": false
}
],
"/category2/": [
{
"text": "知识积累",
"link": "/category2/index",
"items": [
{
"text": "Git and GitHub",
"link": "/category2/git与github"
},
{
"text": "中国ERP应有的功能",
"link": "/category2/The ERP should be in China"
}
],
"collapsed": false
}
]
},
"outline": {
"level": [
1,
6
],
"label": "提纲"
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/linsiwen/"
}
],
"externalLinkIcon": true
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {},
"headers": [],
"relativePath": "category1/api-examples.md",
"filePath": "category1/api-examples.md",
"lastUpdated": 1715794846000
}Page Frontmatter
{}More
Check out the documentation for the full list of runtime APIs.