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
{ "lastUpdated": { "text": "最近更新时间", "formatOptions": { "dateStyle": "short", "timeStyle": "short" } }, "search": { "provider": "algolia", "options": { "appId": "YLWOYZ6XJI", "apiKey": "d46c412d53ca0c1ec4aad7ffaf858a09", "indexName": "helloch", "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": "点击反馈" } } } } }, "nav": [ { "text": "后端", "activeMatch": "/backend/*", "items": [ { "text": "Linux", "link": "/backend/linux", "activeMatch": "/linux/*" }, { "text": "Network", "link": "/backend/net", "activeMatch": "/net/*" }, { "text": "langs", "items": [ { "text": "Golang ", "link": "/backend/golang", "activeMatch": "/golang/*" }, { "text": "Java ", "link": "/backend/java", "activeMatch": "/java/*" } ] }, { "text": "database", "items": [ { "text": "MySQL", "link": "/backend/mysql", "activeMatch": "/mysql/*" }, { "text": "Redis", "link": "/backend/redis", "activeMatch": "/redis/*" } ] }, { "text": "message queue", "items": [ { "text": "Kafka", "link": "/backend/mq/kafka", "activeMatch": "/kafka/*" } ] }, { "text": "Git", "link": "/backend/git", "activeMatch": "/backend/git/*" }, { "text": "Docker", "link": "/backend/docker", "activeMatch": "/backend/docker/*" } ] }, { "text": "前端", "items": [ { "text": "Vue", "link": "/frontend/vue", "activeMatch": "/vue/*" }, { "text": "React", "link": "/frontend/react", "activeMatch": "/react/*" } ] }, { "text": "归档", "link": "/archive", "activeMatch": "/archive/*" }, { "text": "关于", "items": [ { "text": "本站", "link": "/about/site", "activeMatch": "/about/site/*" }, { "text": "日志", "link": "/about/changelog", "activeMatch": "/about/log/*" } ] } ], "sidebar": { "/algo/": [ { "text": "算法", "base": "/algo/", "items": [ { "text": "栈", "link": "/stack" }, { "text": "队列", "link": "/queue" }, { "text": "链表", "link": "/linkedlist" }, { "text": "树", "link": "/tree" }, { "text": "图", "link": "/graph" } ], "collapsed": false } ], "/redis/": [ { "text": "Redis", "base": "/redis/", "items": [ { "text": "Redis 简介", "link": "/" }, { "text": "Redis - 数据类型", "base": "/redis/data-types/", "link": "/", "collapsed": false, "items": [ { "text": "Strings - 字符串", "link": "Strings" }, { "text": "Lists - 列表", "link": "Lists" }, { "text": "Sets - 集合", "link": "Sets" }, { "text": "Hashes - 哈希", "link": "Hashes" }, { "text": "ZSet - 有序集合", "link": "ZSet" }, { "text": "Stream - 流", "link": "Stream" }, { "text": "encoding - 编码", "items": [ { "text": "SDS", "link": "encoding-sds" }, { "text": "ZIPLIST", "link": "encoding-zip-list" }, { "text": "HASHTABLE", "link": "encoding-hashtable" }, { "text": "SKIPLIST", "link": "encoding-skip-list" } ] } ] }, { "text": "Redis - 架构", "base": "/redis/arch/", "link": "/", "collapsed": false, "items": [ { "text": "数据库结构", "link": "redisDb" }, { "text": "单线程模型", "link": "single-thread" }, { "text": "多线程持久化", "link": "multi-thread-persistence" }, { "text": "过期淘汰算法", "link": "LRU-LFU" } ] }, { "text": "Redis - 持久化", "base": "/redis/persistence/", "link": "/", "collapsed": false, "items": [ { "text": "RDB - 数据快照", "link": "RDB" }, { "text": "AOF - 日志记录", "link": "AOF" }, { "text": "AOF&RDB - 混合持久化", "link": "AOF&RDB" } ] }, { "text": "Redis - 应用场景", "base": "/redis/application/", "link": "/", "collapsed": false, "items": [ { "text": "缓存", "link": "cache" }, { "text": "分布式锁", "link": "lock", "items": [ { "text": "Go实现分布式锁", "link": "go-redis-lock" } ] } ] }, { "text": "Redis - 集群", "base": "/redis/cluster/", "link": "/", "collapsed": false, "items": [ { "text": "集群介绍", "link": "intro" } ] }, { "text": "Redis - 命令", "base": "/redis/command/", "link": "/", "collapsed": false, "items": [ { "text": "Redis 键(keys)", "link": "keys" } ] }, { "text": "Redis-interview", "link": "interview" } ], "collapsed": false } ], "/mysql/": [ { "text": "MySQL", "base": "/mysql/", "items": [ { "text": "MySQL索引类型", "link": "/mysql-index" }, { "text": "MySQL事务", "link": "/mysql-transaction" }, { "text": "MySQL锁", "link": "/mysql-lock" }, { "text": "MySQL日志", "link": "/mysql-log" }, { "text": "MySQL内存", "link": "/mysql-buffer-pool" }, { "text": "MySQL逻辑架构", "link": "/mysql-arch" } ], "collapsed": false } ], "/golang/": [ { "text": "Golang", "base": "/golang/", "link": "/", "items": [ { "text": "Golang - 语法", "link": "/principles" }, { "text": "Golang - 原理", "link": "/principles" } ], "collapsed": false } ] }, "socialLinks": [ { "icon": "github", "link": "https://github.com/chhz0" } ], "editLink": { "pattern": "https://github.com/chhz0/helloch.cn/edit/vitepress/docs/:path", "text": "帮助我改善此页面!" }, "docFooter": { "prev": "Prev", "next": "Next" }, "outline": { "label": "页面导航", "level": [ 1, 2 ] }, "returnToTopLabel": "回到顶部", "sidebarMenuLabel": "菜单", "darkModeSwitchLabel": "主题", "lightModeSwitchTitle": "切换到浅色模式", "darkModeSwitchTitle": "切换到深色模式", "externalLinkIcon": true, "footer": { "message": "Released under the <a href=\"https://github.com/chhz0/helloch.cn/blob/main/LICENSE\">MIT License</a>.", "copyright": "Copyright © 2024-2025 chhz0 | <a href=\"http://beian.miit.gov.cn/\" target=\"_blank\">粤ICP备2024347558号</a>" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "frontend/vitepress/api-examples.md", "filePath": "frontend/vitepress/api-examples.md", "lastUpdated": 1741729080000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.