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, "logo": "assets/img/logo.png", "siteTitle": "WeTools", "search": { "provider": "local", "options": { "locales": { "zh": { "translations": { "button": { "buttonText": "搜索文档", "buttonAriaLabel": "搜索文档" }, "modal": { "noResultsText": "无法找到相关结果", "resetButtonTitle": "清除查询条件", "footer": { "selectText": "选择", "navigateText": "切换" } } } } } } }, "nav": [ { "text": "Home", "link": "/" }, { "text": "Team", "link": "/team" }, { "text": "Guides", "items": [ { "text": "Markdown Examples", "link": "/guides/markdown-examples" }, { "text": "Runtime API Examples", "link": "/guides/api-examples" } ] } ], "sidebar": { "/guides/": [ { "text": "Guides", "collapsed": false, "items": [ { "text": "Index", "link": "/guides/" }, { "text": "Markdown Examples", "link": "/guides/markdown-examples" }, { "text": "Runtime API Examples", "link": "/guides/api-examples" } ] } ], "/packages/": [ { "text": "Packages", "collapsed": false, "items": [ { "text": "Index", "link": "/packages/" }, { "text": "WeLink-Themes-Blue 1.0.0", "link": "/packages/WeLink-Themes-Blue-1.0.0" } ] } ] }, "socialLinks": [ { "icon": "github", "link": "https://github.com/yequanrui/WeTools.git" }, { "icon": "npm", "link": "https://www.npmjs.com/~yequanrui" } ], "editLink": { "pattern": "https://github.com/yequanrui/WeTools/edit/master/docs/:path", "text": "Edit this page on GitHub" }, "lastUpdated": { "text": "Updated at", "formatOptions": { "dateStyle": "full", "timeStyle": "medium" } }, "rewrites": { "packages/:pkg(.*)": ":pkg/index.md" }, "footer": { "message": "Released under the MIT License.", "copyright": "Copyright © 2021-present Quanrui Ye" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "guides/api-examples.md", "filePath": "guides/api-examples.md", "lastUpdated": 1725169754000 }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.