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.jpg", "nav": [ { "text": "首页", "link": "/" }, { "text": "技术分享", "link": "/" }, { "text": "实验室", "items": [ { "text": "MQTT 服务器", "link": "http://ethanboy.com:18083" } ] }, { "text": "学习资料", "items": [ { "text": "esp32+微信小程序", "link": "https://trstudio.notion.site/ESP32-3ee773847c6f4916945c8cb7d9a9d502" }, { "text": "20sffactory三轴机械臂", "link": "https://www.20sffactory.com/robot/resource#firmware" }, { "text": "海豚机械臂大作战", "link": "https://www.bilibili.com/cheese/play/ep34520?csource=Hp_searchresult&spm_id_from=333.337.0.0" }, { "text": "立创开发板", "items": [ { "text": "【立创·泰山派】开发板 ", "link": "https://lceda001.feishu.cn/wiki/IJtRwVu5kiylHykl3RJcQ8ANncY" }, { "text": "【立创·ESP32S3R8N8】开发板 ", "link": "https://lceda001.feishu.cn/wiki/PICgwjcDsiN7TjkWw5tc3OzbnHb" } ] }, { "text": "前端技术", "items": [ { "text": "EMQX MQTT 微信小程序接入 ", "link": "https://docs.emqx.com/zh/enterprise/v4.4/development/wechat-miniprogram.html#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99" }, { "text": "使用 WebSocket 连接 MQTT 服务器 ", "link": "https://www.emqx.com/zh/blog/connect-to-mqtt-broker-with-websocket" }, { "text": "微信小程序控制硬件 ", "link": "https://blog.csdn.net/xh870189248/article/details/84070944" }, { "text": "nginx反向代理mqtt", "link": "https://blog.csdn.net/LuoHuaX/article/details/129278224" } ] } ] }, { "text": "站点导航", "link": "/markdown-examples" } ], "sidebar": [ { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/vuejs/vitepress" } ] }
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.