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
{ "head": [ [ "link", { "rel": "icon", "href": "/favicon.ico" } ] ], "socialLinks": [ { "icon": "github", "link": "https://github.com/jxpeng98" } ], "editLink": { "pattern": "https://github.com/jxpeng98/learnalog-vite/edit/main/docs/:path", "text": "Edit this page on GitHub" }, "outline": "deep", "sidebar": { "/statistics-for-insurance/": { "base": "/statistics-for-insurance/", "items": [ { "text": "Introduction", "link": "01-intro/index.md" }, { "text": "Chain Ladder Method", "link": "02-chain-ladder/index.md", "items": [ { "text": "Basic chain ladder", "link": "02-chain-ladder/01-basic-chain" }, { "text": "Average cost per claim", "link": "02-chain-ladder/02-average-per-claim" }, { "text": "Bornhuetter Ferguson (B F) method", "link": "02-chain-ladder/03-b-f-method" } ], "collapsed": true }, { "text": "Common distributions in general Insurance", "link": "03-common-dist/index.md", "items": [ { "text": "Loss distributions", "link": "03-common-dist/01-loss-dist" }, { "text": "More Distributions for Modeling Claim", "link": "03-common-dist/02-more-dist" } ], "collapsed": true } ] }, "/examples/": { "base": "/examples/", "items": [ { "text": "api examples", "link": "api-examples" }, { "text": "Introduction", "link": "markdown-examples" }, { "text": "test for html", "link": "test" } ] } }, "nav": [ { "text": "Home", "link": "/en/" }, { "text": "Academic Resources", "items": [ { "text": "Statistics for Insurance", "link": "en/statistics-for-insurance/01-intro" }, { "text": "Examples", "link": "en/examples/test" } ] } ], "footer": { "message": "Powered by <a href=\"https://vitepress.vuejs.org\" target=\"_blank\" rel=\"noopener noreferrer\">VitePress</a>", "copyright": "Copyright © 2025 PENG Jiaxin" } }
Page Data
{ "title": "Runtime API Examples", "description": "", "frontmatter": { "outline": "deep" }, "headers": [], "relativePath": "en/examples/api-examples.md", "filePath": "en/examples/api-examples.md" }
Page Frontmatter
{ "outline": "deep" }
More
Check out the documentation for the full list of runtime APIs.