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": "Examples",
"link": "/markdown-examples"
},
{
"text": "后端工程",
"link": "/backend/redis"
},
{
"text": "AI 实验室",
"link": "/ai/comfyui"
},
{
"text": "GitHub",
"link": "https://github.com/DaveIW2034"
}
],
"sidebar": [
{
"text": "Examples",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
},
{
"text": "后端工程",
"items": [
{
"text": "Redis 实战",
"link": "/backend/redis"
},
{
"text": "Python Logging",
"link": "/backend/logging"
},
{
"text": "FastAPI TraceID",
"link": "/backend/middleware"
},
{
"text": "PeeWee Postgresql 探活",
"link": "/backend/keep-live"
},
{
"text": "服务注册与发现",
"link": "/backend/registry"
},
{
"text": "RabbitMQ AIO实践",
"link": "/backend/aio-pika"
},
{
"text": "InfluxDB 快速入门与核心概念",
"link": "/backend/influx-db-py"
},
{
"text": "WorkLife 工作",
"link": "/backend/work-life"
},
{
"text": "Pg_parman 工作",
"link": "/backend/pg_parman"
}
]
},
{
"text": "AI 实验室",
"items": [
{
"text": "ComfyUI 实践",
"link": "/ai/comfyui"
},
{
"text": "Codex 实用命令",
"link": "/ai/codex"
},
{
"text": "Codex Worktree结合",
"link": "/ai/worktree"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/DaveIW2034"
}
],
"search": {
"provider": "local"
}
}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.