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": "/guild/index" }, { "text": "组件", "link": "/components/button" } ], "sidebar": [ { "text": "引入", "items": [ { "text": "介绍", "link": "/guild/index" }, { "text": "快速开始", "link": "/guild/quickstart" } ] }, { "text": "基础", "items": [ { "text": "按钮 Button", "link": "/components/button" }, { "text": "布局容器 Container", "link": "/components/container" }, { "text": "图标 Icon", "link": "components/icon" }, { "text": "链接 Link", "link": "/components/link" }, { "text": "折叠面板 Collapse", "link": "/components/collapse" } ] }, { "text": "反馈", "items": [ { "text": "反馈 Alert", "link": "/components/alert" }, { "text": "消息提示 Message", "link": "/components/message" }, { "text": "消息弹出框 MessageBox", "link": "/components/messagebox" }, { "text": "文字提示 Tooltip", "link": "/components/tooltip" }, { "text": "下拉菜单 Dropdown", "link": "/components/dropdown" } ] }, { "text": "数据输入", "items": [ { "text": "开关 Switch", "link": "components/switch" }, { "text": "评分 Rate", "link": "components/rate" }, { "text": "输入框 Input", "link": "components/input" }, { "text": "选择框 Select", "link": "components/select" }, { "text": "表单 Form", "link": "/components/form" }, { "text": "日期选择器 DatePicker", "link": "components/datepicker" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/2WeirDo/weirdo-ui" }, { "icon": "x", "link": "https://2weirdo.github.io/", "ariaLabel": "Blog" } ], "logo": "/logo.png" }
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.