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
{ "blog": { "title": "My AI Written Blog", "description": "All these articles were written by AI!", "defaultAuthor": "AI Writer", "categoryIcons": { "article": "i-[carbon/notebook]", "tutorial": "i-[carbon/book]", "document": "i-[carbon/document]" }, "tagIcons": { "github": "i-[carbon/logo-github]", "vue": "i-[carbon/logo-vue]", "web development": "i-[carbon/development]", "javascript": "i-[logos/javascript]", "html": "i-[logos/html-5]" }, "dateConfig": { "format": "yyyy/MM/dd", "locale": { "code": "en-US", "formatLong": {}, "localize": {}, "match": {}, "options": { "weekStartsOn": 0, "firstWeekContainsDate": 1 } } }, "giscus": { "repo": "chunge16/vitepress-blogs-theme", "repoId": "R_kgDOKzaaEg", "category": "General", "categoryId": "DIC_kwDOKzaaEs4CbyYB", "mapping": "pathname", "inputPosition": "top", "lang": "zh-CN", "lightTheme": "light", "darkTheme": "transparent_dark", "defaultEnable": true } }, "socialLinks": [ { "icon": "github", "link": "https://github.com/chunge16/vitepress-blogs-theme" } ], "search": { "provider": "local", "options": { "locales": { "zh": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } } } } }, "nav": [ { "text": "指南", "link": "/zh/guide/what-is-vitepress-blog", "activeMatch": "/zh/guide/" }, { "text": "配置", "link": "/zh/reference/config", "activeMatch": "/zh/reference/" }, { "text": "示例", "items": [ { "text": "Markdown", "link": "/zh/markdown-examples" }, { "text": "api-examples", "link": "/zh/api-examples" }, { "text": "Theme Test", "link": "/zh/theme-test" } ] }, { "text": "博客", "activeMatch": "/zh/blog/", "items": [ { "text": "博客首页", "link": "/zh/blog/", "activeMatch": "/zh/blog/$" }, { "text": "标签", "link": "/zh/blog/tags", "activeMatch": "/zh/blog/tags" }, { "text": "归档", "link": "/zh/blog/archives", "activeMatch": "/zh/blog/archives" } ] }, { "text": "0.2.4", "items": [ { "text": "更新日志", "link": "https://github.com/chunge16/vitepress-blogs-theme/blob/main/CHANGELOG.md" } ] } ], "sidebar": { "/zh/guide/": [ { "text": "介绍", "collapsed": false, "items": [ { "text": "什么是 VitePress Blog?", "link": "/zh/guide/what-is-vitepress-blog" }, { "text": "快速开始", "link": "/zh/guide/getting-started" }, { "text": "致谢", "link": "/zh/guide/credits" } ] }, { "text": "Frontmatter 配置", "collapsed": false, "items": [ { "text": "博客 Frontmatter", "link": "/zh/guide/frontmatter-post" }, { "text": "作者 Frontmatter", "link": "/zh/guide/frontmatter-author" } ] }, { "text": "配置和API参考", "link": "/zh/reference/config" } ], "/zh/reference/": [ { "text": "参考", "items": [ { "text": "站点配置", "link": "/zh/reference/config" }, { "text": "Tailwind", "link": "/zh/reference/tailwind" }, { "text": "Icons", "link": "/zh/reference/icons" } ] } ] }, "docFooter": { "prev": "上一页", "next": "下一页" }, "returnToTopLabel": "返回顶部", "outlineTitle": "导航栏", "darkModeSwitchLabel": "外观", "sidebarMenuLabel": "归档", "lastUpdatedText": "更新于", "footer": { "message": "我只是尽力将工具做得更好,如果可以的话欢迎给一个 <a c-orange-5 target=\"_blank\" href=\"https://github.com/chunge16/vitepress-blogs-theme\">star ⭐</a>", "copyright": "MIT Licensed | 版权所有 © 2023-2024 <a target=\"_blank\" href=\"https://github.com/chunge16\">chunge16</a>" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "zh/api-examples.md", "filePath": "zh/api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.