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" }, "nav": [ { "text": "Guide", "link": "/guide/what-is-vitepress-blog", "activeMatch": "/guide/" }, { "text": "Reference", "link": "/reference/config", "activeMatch": "/reference/" }, { "text": "Examples", "items": [ { "text": "Markdown", "link": "/markdown-examples" }, { "text": "api-examples", "link": "/api-examples" }, { "text": "Theme Test", "link": "/theme-test" } ] }, { "text": "Blog", "activeMatch": "/blog/", "items": [ { "text": "Blog Home", "link": "/blog/", "activeMatch": "/blog/$" }, { "text": "Tags", "link": "/blog/tags", "activeMatch": "/blog/tags" }, { "text": "Archives", "link": "/blog/archives", "activeMatch": "/blog/archives" } ] }, { "text": "0.2.4", "items": [ { "text": "Changelog", "link": "https://github.com/chunge16/vitepress-blogs-theme/blob/main/CHANGELOG.md" } ] } ], "sidebar": { "/guide/": [ { "text": "Introduction", "collapsed": false, "items": [ { "text": "What is VitePress Blog?", "link": "/guide/what-is-vitepress-blog" }, { "text": "Getting Started", "link": "/guide/getting-started" }, { "text": "Credits", "link": "/guide/credits" } ] }, { "text": "Frontmatter Config", "collapsed": false, "items": [ { "text": "Post Frontmatter", "link": "/guide/frontmatter-post" }, { "text": "Author Frontmatter", "link": "/guide/frontmatter-author" } ] }, { "text": "Config & API Reference", "link": "/reference/config" } ], "/reference/": [ { "text": "Reference", "items": [ { "text": "Site Config", "link": "/reference/config" }, { "text": "Tailwind", "link": "/reference/tailwind" }, { "text": "Icons", "link": "/reference/icons" } ] } ] }, "docFooter": { "prev": "Previous page", "next": "Next page" }, "returnToTopLabel": "Return to top", "outlineTitle": "On this page", "darkModeSwitchLabel": "Appearance", "sidebarMenuLabel": "Menu", "lastUpdatedText": "Last updated", "footer": { "message": "I just try my best to make thing well, Could you give a <a c-orange-5 target=\"_blank\" href=\"https://github.com/chunge16/vitepress-blogs-theme\">star ⭐</a>", "copyright": "MIT Licensed | Copyright © 2023-2024 <a target=\"_blank\" href=\"https://github.com/chunge16\">chunge16</a>" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "api-examples.md", "filePath": "api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.