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
{
"nav": [
{
"text": "Home",
"link": "/en_us/"
}
],
"sidebar": {
"/": [
{
"text": "回到主页",
"link": "/"
},
{
"text": "示例文档",
"items": [
{
"text": "Markdown 示例",
"link": "/markdown-examples"
},
{
"text": "API 示例",
"link": "/api-examples"
}
]
},
{
"text": "外链示例",
"link": "https://not-exist.wss.moe/outlink-zh"
}
],
"/en_us/": [
{
"text": "Back to homepage",
"link": "/en_us/"
},
{
"text": "Example docs",
"items": [
{
"text": "Markdown Examples",
"link": "/en_us/markdown-examples"
},
{
"text": "API Examples",
"link": "/en_us/api-examples"
}
]
},
{
"text": "Outlink Test",
"link": "https://not-exist.wss.moe/outlink-en"
}
]
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
},
{
"icon": "discord",
"link": "https://not-exist.wss.moe/discord"
}
],
"editLink": {
"pattern": "https://github.com/wyf9/vitepress-template/edit/main/:path",
"text": "Edit this page on GitHub"
},
"lastUpdated": {
"text": "Last updated at",
"formatOptions": {
"dateStyle": "full",
"timeStyle": "full"
}
}
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "en_us/api-examples.md",
"filePath": "en_us/api-examples.md",
"lastUpdated": 1765629995000
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.