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": "/logo.svg",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "WebSocket",
"link": "/websocket/"
},
{
"text": "MQTT",
"link": "/mqtt/"
},
{
"text": "RESTful",
"link": "/restful/"
},
{
"text": "Examples",
"link": "/example/markdown-examples"
}
],
"sidebar": {
"/websocket/": [
{
"text": "WebSocket Service",
"collapsed": false,
"items": [
{
"text": "Overview",
"link": "/websocket/"
},
{
"text": "Deployment",
"link": "/websocket/deployment"
},
{
"text": "HTTP API",
"link": "/websocket/api"
}
]
}
],
"/restful/": [
{
"text": "RESTful API",
"collapsed": false,
"items": [
{
"text": "概览",
"link": "/restful/"
},
{
"text": "设计规范",
"link": "/restful/standards"
},
{
"text": "实践案例",
"link": "/restful/examples"
}
]
}
],
"/mqtt/": [
{
"text": "MQTT Service",
"collapsed": false,
"items": [
{
"text": "Overview",
"link": "/mqtt/"
},
{
"text": "Broker Setup",
"link": "/mqtt/broker"
},
{
"text": "Client Guide",
"link": "/mqtt/client"
}
]
}
],
"/example/": [
{
"text": "Examples",
"collapsed": false,
"items": [
{
"text": "Markdown Examples",
"link": "/example/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/example/api-examples"
}
]
}
]
},
"search": {
"provider": "local",
"options": {
"locales": {
"root": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"noResultsText": "无法找到相关结果",
"resetButtonTitle": "清除查询条件",
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭"
}
}
}
}
}
}
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "example/api-examples.md",
"filePath": "example/api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.