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": "/"
},
{
"text": "基础篇 (HCIA)",
"link": "docs/01-basics/01-what-is-network"
},
{
"text": "进阶篇 (HCIP)",
"link": "docs/02-advanced/index"
},
{
"text": "专家篇 (HCIE)",
"link": "docs/03-expert/index"
}
],
"sidebar": [
{
"text": "第一章:网络基础 (Basics)",
"items": [
{
"text": "0.1 什么是计算机网络",
"link": "docs/01-basics/01-what-is-network"
},
{
"text": "0.2 网络拓扑 (Topology)",
"link": "docs/01-basics/02-topology"
},
{
"text": "0.3 OSI vs TCP/IP 模型",
"link": "docs/01-basics/03-osi-model"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/你的GitHub用户名/Network101"
}
],
"footer": {
"copyright": "<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">鲁ICP备19054621号</a>"
}
}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.