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.png", "search": { "provider": "local" }, "socialLinks": [ { "icon": "github", "link": "https://github.com/vuejs/vitepress" } ], "docFooter": { "prev": "上一页", "next": "下一页" }, "outline": { "label": "本页内容" }, "nav": [ { "text": "首页", "link": "/zh/" }, { "text": "财富", "link": "/zh/finance/how-much-money-do-you-need-to-be-in-the-top-1-percent" }, { "text": "消费电子", "link": "/zh/electronics/global-smartphone-market-share-counterpoint-2024" }, { "text": "网址推荐", "link": "/zh/sites/aiTool2" }, { "text": "测试", "items": [ { "text": "测试1", "link": "/zh/test/test1" } ] } ], "sidebar": { "/zh/markdown-examples": { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/zh/markdown-examples" }, { "text": "Runtime API Examples", "link": "/zh/api-examples" } ] }, "/zh/electronics/": { "text": "消费电子榜单", "items": [ { "text": "全球手机市场", "link": "/zh/electronics/global-smartphone-market-share-counterpoint-2024" }, { "text": "中国时间市场", "link": "/zh/electronics/china-smartphone-market-share-counterpoint-2024" }, { "text": "测试4", "link": "/zh/zhWealthThresholdChart" } ] }, "/zh/sites/": { "text": "网址推荐", "items": [ { "text": "精选AI工具", "link": "/zh/sites/aiTool2" }, { "text": "常用商业软件开源免费替代品", "link": "zh/sites/free-alternatives-to-commercial-software.md" }, { "text": "适合孩子观看的纪录片", "link": "/zh/sites/kid-friendly-documentaries-guide" }, { "text": "视频生成网站和工具", "link": "/zh/sites/video-creation-websites-and-tools" } ] } } }
Page Data
{ "title": "Runtime API Examples(中文)", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "zh/api-examples.md", "filePath": "zh/api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.