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": "/"
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/VM-Chinese-translate-group"
},
{
"icon": "bilibili",
"link": "https://space.bilibili.com/2085089798"
}
],
"sidebar": [
{
"text": "VMTU",
"items": [
{
"text": "模组简介",
"link": "/vmtu/"
},
{
"text": "配置文件",
"link": "/vmtu/config"
},
{
"text": "自动切换语言",
"link": "/vmtu/language"
},
{
"text": "模组安装检测",
"link": "/vmtu/mod-check"
},
{
"text": "资源包相关",
"link": "/vmtu/resourcepack"
},
{
"text": "汉化更新检测",
"link": "/vmtu/translation-update"
},
{
"text": "支持的模组加载器及版本",
"link": "/vmtu/supported-version"
},
{
"text": "VM Metadata",
"link": "/vmtu/metadata"
}
]
},
{
"text": "文档样式示例",
"items": [
{
"text": "Markdown 示例",
"link": "example/markdown"
},
{
"text": "API 示例",
"link": "example/api"
},
{
"text": "组件示例",
"link": "example/component"
}
]
}
],
"search": {
"provider": "algolia",
"options": {
"appId": "TTUZ1AK1BJ",
"apiKey": "079af68ecd924c327b5ee9591e0dd829",
"indexName": "VM-Docs"
}
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "example/api.md",
"filePath": "example/api.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.