Runtime API Examples
更新: 1/11/2025 字数: 0 字 时长: 0 分钟
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
{
"langMenuLabel": "切换语言",
"darkModeSwitchLabel": "主题",
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式",
"sidebarMenuLabel": "菜单",
"outline": {
"level": [
2,
3
],
"label": "目录"
},
"returnToTopLabel": "返回顶部",
"lastUpdated": {
"text": "更新于"
},
"docFooter": {
"prev": "上一篇",
"next": "下一篇"
},
"editLink": {
"pattern": "https://github.com/TransSoul/WeightLoss-Diary/blob/main/docs/:path",
"text": "在 GitHub 上编辑此页面"
},
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"noResultsText": "无法找到相关结果",
"resetButtonTitle": "清除查询条件",
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭"
}
}
}
}
},
"sidebar": [],
"nav": [
{
"text": "Home",
"link": "/"
},
{
"text": "Examples",
"link": "/markdown-examples"
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/TransSoul/"
}
],
"footer": {
"message": "Released under the MIT License.",
"copyright": "Copyright © 2024-present TransSoul"
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "contribution.md",
"filePath": "contribution.md",
"lastUpdated": 1736605902000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.