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": "/avatar.png",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "开发",
"items": [
{
"text": "数据结构与算法",
"link": "/column/Algorithm/"
}
]
},
{
"text": "动漫",
"items": [
{
"text": "数据结构与算法",
"link": "/column/fan/"
}
]
},
{
"text": "关于我",
"items": [
{
"text": "Github",
"link": "https://github.com/Jacqueline712"
},
{
"text": "bilibili",
"link": "https://juejin.cn/user/3131845139247960/posts"
},
{
"text": "抖音",
"link": "https://pzfqk98jn1.feishu.cn/wiki/space/7193915595975491587?ccm_open_type=lark_wiki_spaceLink"
}
]
}
],
"sidebar": {
"/column/Algorithm/": [
{
"text": "首页",
"link": "/column/Algorithm/index"
},
{
"text": "栈和队列",
"items": [
{
"text": "栈-深拷贝和浅拷贝",
"link": "/column/Algorithm/001_Stack"
},
{
"text": "队列-事件循环",
"link": "/column/Algorithm/002_Queue"
}
]
},
{
"text": "字典和树",
"items": [
{
"text": "字典和集合-Set和Map",
"link": "/column/Algorithm/003_Dictionary"
},
{
"text": "树-深/广度优先遍历",
"link": "/column/Algorithm/004_Tree"
}
]
}
]
},
"search": {
"provider": "local"
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
],
"outline": {
"level": [
2,
6
],
"label": "目录"
}
}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.