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
{ "i18nRouting": true, "logo": "/images/lng.png", "nav": [ { "text": "主页", "link": "/" }, { "text": "基础手册", "link": "/basis/lng" } ], "sidebar": { "/test/": [ { "text": "Examples", "items": [ { "text": "Markdown Examples", "link": "/markdown-examples" }, { "text": "Runtime API Examples", "link": "/api-examples" } ] } ], "/basis/": [ { "text": "基础手册", "items": [ { "text": "1 LNG", "link": "/basis/lng", "items": [ { "text": "1.1 质量标准", "link": "/basis/lng-2" }, { "text": "1.2 单位换算", "link": "/basis/lng-1" } ] }, { "text": "2 国际贸易", "link": "/basis/trade", "items": [ { "text": "2.1 发展趋势", "link": "/basis/trade2024" }, { "text": "2.2 发展历史", "link": "/basis/history" }, { "text": "2.3 贸易类型", "link": "/basis/types" } ] }, { "text": "LNG产业链", "link": "/basis/lng-industry" }, { "text": "主要玩家", "items": [ { "text": "卡塔尔", "link": "/basis/player/qatar" }, { "text": "ADNOC", "link": "/basis/player/adnoc" } ] }, { "text": "中国接收站", "link": "/basis/terminal/", "items": [ { "text": "大鹏", "link": "/basis/terminal/dapeng" }, { "text": "盐城滨海", "link": "/basis/terminal/yanchengbinghai" } ] } ] } ] }, "socialLinks": [ { "icon": "github", "link": "https://github.com/cowbook/lng" } ] }
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.