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": "/favicon.png",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "arch",
"link": "/notes/archlinux/index"
}
],
"sidebar": {
"/notes/archlinux/": [
{
"text": "Archlinux",
"collapsible": false,
"items": [
{
"text": "Index",
"link": "/notes/archlinux/index"
},
{
"text": "安装",
"link": "/notes/archlinux/install"
},
{
"text": "Gnome",
"link": "/notes/archlinux/gnome"
},
{
"text": "修改根分区大小",
"link": "/notes/archlinux/changeRootSize"
},
{
"text": "VS Code 部分快捷键无法生效",
"link": "/notes/archlinux/vscodeShortCuts"
},
{
"text": "删除系统",
"link": "/notes/archlinux/deleteOS"
}
]
}
]
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/yoshino-nya"
},
{
"icon": {
"svg": "<?xml version=\"1.0\"?><svg role=\"img\" viewBox=\"0 0 24 24\" \n xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M4.5 7.5C5.328 7.5 6 8.172 \n 6 9v10.5c0 .828-.672 1.5-1.5 1.5h-3C.673 21 0 20.328 0 19.5V9c0-.828.673-1.5 \n 1.5-1.5h3zm9-4.5c.828 0 1.5.672 1.5 1.5v15c0 .828-.672 1.5-1.5 1.5h-3c-.827 \n 0-1.5-.672-1.5-1.5v-15c0-.828.673-1.5 1.5-1.5h3zm9 7.5c.828 0 1.5.672 1.5 1.5v7.5c0 \n .828-.672 1.5-1.5 1.5h-3c-.828 0-1.5-.672-1.5-1.5V12c0-.828.672-1.5 1.5-1.5h3z\"/></svg>"
},
"link": "https://codeforces.com/profile/Zhangwuji"
}
],
"docFooter": {
"prev": "上一页",
"next": "下一页"
},
"lastUpdatedText": "最后更新于",
"editLink": {
"pattern": "https://github.com/yoshino-nya/new_blog/edit/main/docs/:path",
"text": "在 GitHub 上编辑此页"
},
"outline": {
"label": "页面导航"
},
"returnToTopLabel": "回到顶部",
"sidebarMenuLabel": "菜单",
"darkModeSwitchLabel": "主题",
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式"
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1762307210000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.