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": "V2ray", "link": "/v2ray/v2ray 客户端 Linux" } ], "sidebar": [ { "text": "1. v2ray", "items": [ { "text": "v2ray 客户端 Linux", "link": "/v2ray/v2ray 客户端 Linux" }, { "text": "v2ray 客户端 macOS", "link": "/v2ray/v2ray 客户端 macOS" }, { "text": "v2ray 客户端 Windows", "link": "/v2ray/v2ray 客户端 Windows" }, { "text": "v2ray 服务器配置", "link": "/v2ray/v2ray 服务器配置" }, { "text": "v2ray 谷歌浏览器插件使用", "link": "/v2ray/v2ray 谷歌浏览器插件使用" } ] }, { "text": "2. 五笔码表助手", "items": [ { "text": "五笔码表助手", "link": "/wubiDictEditor/wubi-dict-editor" }, { "text": "码表处理工具", "link": "/wubiDictEditor/tool" } ] }, { "text": "〇、预设", "items": [ { "text": "Markdown 例子", "link": "/preset/markdown-examples" }, { "text": "API 例子", "link": "/preset/api-examples" } ] } ], "socialLinks": [ { "icon": "github", "link": "https://github.com/vuejs/vitepress" } ] }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "preset/api-examples.md", "filePath": "preset/api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.