Runtime API Examples
字数: 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>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Results
Theme Data
{
"outline": "deep",
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式",
"lastUpdated": {
"text": "最后更新时间",
"formatOptions": {
"dateStyle": "medium",
"timeStyle": "short"
}
},
"editLink": {
"pattern": "https://github.com/1411430556/vitepress/edit/main/docs/:path",
"text": "在 GitHub 上编辑此页"
},
"docFooter": {
"prev": "上一页",
"next": "下一页"
},
"logo": "/游戏机_game-ps.svg",
"nav": [
{
"text": "v1.0.2",
"items": [
{
"text": "主页",
"link": "/index.md"
},
{
"text": "提 Issues",
"link": "https://github.com/1411430556/vitepress/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen"
},
{
"text": "哔哩哔哩",
"link": "https://space.bilibili.com/44113085"
},
{
"component": "RainbowAnimationSwitcher",
"props": {
"text": "彩虹动画"
}
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/1411430556/vitepress"
},
{
"icon": "bilibili",
"link": "https://space.bilibili.com/44113085"
}
],
"footer": {
"message": "Released under the MIT License.",
"copyright": "Copyright © 2025-present <a target=\"_blank\" href=\"https://github.com/1411430556\">COYG⚡️</a>"
},
"algolia": {
"appId": "ENMGRL79Z2",
"apiKey": "e380fd3a85e623eb7b04ee69ee7bb9c1",
"indexName": "Secretly Diary",
"placeholder": "请输入关键词",
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"searchBox": {
"resetButtonTitle": "清除查询条件",
"resetButtonAriaLabel": "清除查询条件",
"cancelButtonText": "取消",
"cancelButtonAriaLabel": "取消"
},
"startScreen": {
"recentSearchesTitle": "搜索历史",
"noRecentSearchesText": "没有搜索历史",
"saveRecentSearchButtonTitle": "保存至搜索历史",
"removeRecentSearchButtonTitle": "从搜索历史中移除",
"favoriteSearchesTitle": "收藏",
"removeFavoriteSearchButtonTitle": "从收藏中移除"
},
"errorScreen": {
"titleText": "无法获取结果",
"helpText": "你可能需要检查你的网络连接"
},
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭",
"searchByText": "搜索提供者"
},
"noResultsScreen": {
"noResultsText": "无法找到相关结果",
"suggestedQueryText": "你可以尝试查询",
"reportMissingResultsText": "你认为该查询应该有结果?",
"reportMissingResultsLinkText": "点击反馈"
}
}
}
},
"externalLinkIcon": true,
"sidebar": [
{
"text": "壁纸推荐",
"items": [
{
"text": "Wallpaper精选壁纸推荐1️⃣",
"link": "/壁纸推荐/1-Wallpaper精选壁纸推荐"
}
],
"collapsed": false
},
{
"text": "游戏新闻",
"items": [
{
"text": "MSI半决赛:T1 3-2 AL",
"link": "/游戏新闻/1-MSI半决赛"
},
{
"text": "MSI T1赛后采访",
"link": "/游戏新闻/2-MSI T1赛后采访"
},
{
"text": "T1 2:1 GEN:27连胜已成过往",
"link": "/游戏新闻/3-T1 2比1 GEN让一追二大胜GEN"
}
],
"collapsed": false
},
{
"text": "策略",
"items": [
{
"text": "图书馆30秒",
"link": "/策略/1-图书馆30秒"
},
{
"text": "Vitepress链接添加动态渐变色",
"link": "/策略/2-链接添加动态渐变色"
}
],
"collapsed": false
},
{
"text": "编程",
"items": [
{
"text": "Vue笔记",
"link": "/编程/1-Vue笔记"
},
{
"text": "Vue3快速上手",
"link": "/编程/2-Vue3快速上手"
},
{
"text": "数据库录入指南",
"link": "/编程/3-数据库录入指南"
},
{
"text": "角色支持介绍",
"link": "/编程/4-角色支持介绍"
},
{
"text": "示例展示",
"link": "/编程/5-示例展示"
},
{
"text": "图书馆30秒",
"link": "/编程/6-图书馆30秒"
},
{
"text": "Go初学者",
"link": "/编程/7-Go初学者"
},
{
"text": "Api-Examples",
"link": "/编程/8-api-examples"
},
{
"text": "ZZZ_Simulator",
"link": "/编程/9-ZZZ_Simulator"
},
{
"text": "ZZZ模拟器",
"link": "/编程/10-ZZZ模拟器"
},
{
"text": "GitHub Emoji表情",
"link": "/编程/11-GitHub emoji表情"
}
],
"collapsed": false
}
]
}Page Data
{
"title": "api-examples",
"description": "",
"frontmatter": {
"title": "api-examples",
"order": 7
},
"headers": [],
"relativePath": "编程/8-api-examples.md",
"filePath": "编程/8-api-examples.md",
"lastUpdated": 1752494279000
}Page Frontmatter
{
"title": "api-examples",
"order": 7
}More
Check out the documentation for the full list of runtime APIs.
js
/**
* @type {import('vitepress').UserConfig}
*/
const config = {
// ...
}
export default config1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
ts
import type { UserConfig } from 'vitepress'
const config: UserConfig = {
// ...
}
export default config1
2
3
4
5
6
7
2
3
4
5
6
7