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": "使用说明",
"link": "/base/base"
},
{
"text": "键位说明",
"link": "/layer/layer"
}
],
"sidebar": [
{
"text": "一、基础",
"items": [
{
"text": "使用说明",
"link": "/base/base"
}
]
},
{
"text": "二、层级说明",
"items": [
{
"text": "层级说明",
"link": "/layer/layer"
}
]
},
{
"text": "三、高级",
"items": [
{
"text": "自定义键位",
"link": "/layer/layer"
},
{
"text": "生成固件",
"link": "/layer/layer"
}
]
},
{
"text": "〇、预设",
"items": [
{
"text": "Markdown 例子",
"link": "/preset/markdown-examples"
},
{
"text": "API 例子",
"link": "/preset/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/KyleBing/bb-readme"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "preset/api-examples.md",
"filePath": "preset/api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.