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
{ "i18nRouting": true, "siteTitle": "知识积累", "lastUpdated": { "text": "最后修改时间:", "formatOptions": { "dateStyle": "full", "timeStyle": "medium", "formatMatcher": "basic", "forceLocale": true }, "carbonAds": { "code": "your-carbon-code", "placement": "your-carbon-placement" } }, "search": { "provider": "local", "options": { "locales": { "zh": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } }, "en": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } } } } }, "editLink": { "pattern": "https://github.com/vuejs/vitepress/edit/main/docs/:path", "text": "Edit this page on GitHub" }, "nav": [ { "text": "首页", "link": "/" }, { "text": "示例", "link": "/example/markdown-examples" }, { "text": "Jenkins", "link": "/jenkins/jenkins" } ], "sidebar": [ { "text": "API举例", "items": [ { "text": "Markdown 示例", "link": "/example/markdown-examples" }, { "text": "Runtime API 示例", "link": "/example/api-examples" } ] }, { "text": "用法", "items": [ { "text": "Jenkins", "link": "/jenkins/jenkins" }, { "text": "Docker", "collapsed": true, "items": [ { "text": "install", "link": "/docker/docker-install" }, { "text": "registry", "link": "/docker/docker-registry" } ] }, { "text": "ECS", "collapsed": true, "items": [ { "text": "阿里ECS", "link": "/ECS/ali-ecs" }, { "text": "Debian安装Docker", "link": "/ECS/Debian-install-Docker" }, { "text": "Debian防火墙", "link": "/ECS/iptables" }, { "text": "squid", "link": "/ECS/squid" }, { "text": "亚马逊EC2", "link": "/ECS/amazon-ec2" } ] }, { "text": "ollama", "link": "/ollama/ollama" } ] } ], "darkModeSwitchLabel": "变深色", "lightModeSwitchTitle": "变浅色", "darkModeSwitchTitle": "切换", "returnToTopLabel": "顶部", "langMenuLabel": "切换语言", "socialLinks": [ { "icon": "github", "link": "https://github.com/vuejs/vitepress" } ], "docFooter": { "prev": "上一篇", "next": "下一篇" }, "footer": { "message": "备案信息", "copyright": "© 2025 个人知识积累 | <a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">冀ICP备2025116312号-2</a>" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "example/api-examples.md", "filePath": "example/api-examples.md", "lastUpdated": 1748267113000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.