Appearance
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": "",
"nav": [
{
"text": "主页",
"link": "/"
},
{
"text": "Examples",
"link": "/markdown-examples"
}
],
"sidebar": [
{
"text": "永恒:幻境 开发文档",
"items": [
{
"text": "项目指引",
"link": "/Guide/GuidePage"
},
{
"text": "协作开发指南",
"link": "/api-example"
},
{
"text": "管理内容",
"link": "",
"collapsed": true,
"items": [
{
"text": "文件夹结构",
"link": ""
}
]
},
{
"text": "程序开发",
"link": "/ProjDev/Rules",
"collapsed": true,
"items": [
{
"text": "项目规范",
"link": "/ProjDev/Rules"
}
]
},
{
"text": "游戏文本",
"link": "/TextContent/GameTextContent"
},
{
"text": "做个测试",
"collapsed": true,
"items": [
{
"text": "ceshi"
}
]
}
]
}
],
"docFooter": {
"prev": "上一页",
"next": "下一页"
},
"outline": {
"level": [
2,
4
],
"label": "页面导航"
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.