模式切换
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
{
"siteTitle": false,
"nav": [
{
"text": "主页",
"link": "/"
},
{
"text": "指南",
"link": "/guide/index"
},
{
"text": "交流群",
"link": "/guide/index"
}
],
"sidebar": {
"guide": [
{
"text": "基础",
"items": [
{
"text": "月令",
"link": "/guide/月令"
},
{
"text": "日辰",
"link": "/guide/日辰"
},
{
"text": "六合",
"link": "/guide/六合"
}
]
}
]
},
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"displayDetails": "显示详细列表",
"resetButtonTitle": "清除查询条件",
"backButtonTitle": "2025",
"noResultsText": "无法找到相关结果",
"footer": {
"selectText": "选择",
"selectKeyAriaLabel": "134",
"navigateText": "切换",
"navigateUpKeyAriaLabel": "456",
"navigateDownKeyAriaLabel": "789",
"closeText": "关闭",
"closeKeyAriaLabel": "2026"
}
}
}
}
},
"outline": {
"label": "本页目录",
"level": [
2,
6
]
},
"sidebarMenuLabel": "菜单",
"returnToTopLabel": "返回顶部",
"darkModeSwitchLabel": "模式切换",
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式",
"docFooter": {
"next": false,
"prev": false
},
"externalLinkIcon": true
}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.