运行时 API 示例
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": "https://avatars.githubusercontent.com/u/169712528",
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/1224HuangJin/Vitepress-Template"
},
{
"icon": "discord",
"link": "https://discord.com/app"
}
],
"search": {
"provider": "local",
"options": {
"locales": {
"root": {
"translations": {
"button": {
"buttonText": "搜索",
"buttonAriaLabel": "搜索"
},
"modal": {
"displayDetails": "显示详细列表",
"resetButtonTitle": "重置搜索",
"backButtonTitle": "关闭搜索",
"noResultsText": "没有结果",
"footer": {
"selectText": "选择",
"selectKeyAriaLabel": "输入",
"navigateText": "导航",
"navigateUpKeyAriaLabel": "上箭头",
"navigateDownKeyAriaLabel": "下箭头",
"closeText": "关闭",
"closeKeyAriaLabel": "Esc"
}
}
}
}
}
}
},
"editLink": {
"pattern": "https://github.com/1224HuangJin/Vitepress-Template/edit/main/:path",
"text": "在 GitHub 上编辑本页"
},
"lastUpdated": {
"text": "最后更新于",
"formatOptions": {
"dateStyle": "full",
"timeStyle": "full",
"forceLocale": true
}
},
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "MarkDown 示例",
"link": "/markdown-examples"
},
{
"text": "API 示例",
"link": "/api-examples"
}
],
"sidebar": [
{
"text": "侧边栏·一",
"items": [
{
"text": "API 示例",
"link": "/api-examples"
}
]
},
{
"text": "侧边栏·二",
"items": [
{
"text": "MarkDown 示例",
"link": "/markdown-examples"
}
]
}
],
"footer": {
"message": "本网站上的所有内容均根据 ... License",
"copyright": "Copyright © 2026 1224HuangJin"
}
}Page Data
{
"title": "运行时 API 示例",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1775501112000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.