主题切换
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
{
"search": {
"provider": "local"
},
"nav": [
{
"text": "主页",
"link": "/"
},
{
"text": "讨论",
"link": "/markdown-examples"
},
{
"text": "使用帮助",
"link": "/content/help/help"
},
{
"text": "项目管理",
"link": "/content/help/help"
},
{
"text": "常用软件",
"link": "/content/help/help"
},
{
"text": "历史版本",
"items": [
{
"text": "Item A",
"link": "/item-1"
},
{
"text": "Item B",
"link": "/item-2"
},
{
"text": "Item C",
"link": "/item-3"
}
]
},
{
"text": "用户登录",
"link": "/content/help/help"
}
],
"aside": "left",
"outline": [
1,
6
],
"footer": {
"message": "Released under the MIT License.",
"copyright": "Copyright © 2019-present Evan You"
},
"lastUpdated": {
"text": "更新于",
"formatOptions": {
"dateStyle": "full",
"timeStyle": "medium"
}
},
"darkModeSwitchLabel": "主题切换",
"lightModeSwitchTitle": "切换至亮色主题",
"darkModeSwitchTitle": "切换至暗色主题",
"sidebarMenuLabel": "导航栏",
"returnToTopLabel": "回至顶部",
"externalLinkIcon": true
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1768275122000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.