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": "Home",
"link": "/"
},
{
"text": "Examples",
"link": "/markdown-examples"
}
],
"sidebar": [
{
"text": "Runtime API Examples",
"link": "/api-examples"
},
{
"text": "fast",
"items": [
{
"text": "指导手册",
"link": "/fast/AGENTS"
},
{
"text": "BASIC",
"link": "/fast/BASIC"
},
{
"text": "记录",
"link": "/fast/RECORDS"
},
{
"text": "chapters",
"items": [
{
"text": "第一章 抓奸倒计时",
"link": "/fast/chapters/001"
},
{
"text": "第二章 你们想看的不是抓奸",
"link": "/fast/chapters/002"
},
{
"text": "第三章 现场改名:投药案",
"link": "/fast/chapters/003"
},
{
"text": "第四章 主谋到场,先扣一顶帽子",
"link": "/fast/chapters/004"
},
{
"text": "第五章 醒来先怀疑我",
"link": "/fast/chapters/005"
},
{
"text": "第六章 热搜不是刀,是证据库",
"link": "/fast/chapters/006"
},
{
"text": "第七章 录音一出,谁是替罪羊",
"link": "/fast/chapters/007"
},
{
"text": "第八章 证人接应失败",
"link": "/fast/chapters/008"
},
{
"text": "第九章 我一个人去",
"link": "/fast/chapters/009"
},
{
"text": "第十章 他们要把你变成“疯子”",
"link": "/fast/chapters/010"
},
{
"text": "第十一章 我不信她,但我站她这边",
"link": "/fast/chapters/011"
},
{
"text": "第十二章 直播门口,体面碎了",
"link": "/fast/chapters/012"
},
{
"text": "第十三章 律师团不是法官",
"link": "/fast/chapters/013"
},
{
"text": "第十四章 他们要你“意外”死",
"link": "/fast/chapters/014"
},
{
"text": "第十五章 欠你一条命",
"link": "/fast/chapters/015"
},
{
"text": "第十六章 抓到陆闻",
"link": "/fast/chapters/016"
},
{
"text": "第十七章 切割声明,逼供电话",
"link": "/fast/chapters/017"
},
{
"text": "第十八章 救回证人,录下名字",
"link": "/fast/chapters/018"
},
{
"text": "第十九章 车祸不是意外",
"link": "/fast/chapters/019"
}
],
"collapsed": false
}
],
"collapsed": false
},
{
"text": "Markdown Extension Examples",
"link": "/markdown-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.