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": "/"
},
{
"text": "JavaScript",
"link": "/javascript/js-inherit",
"activeMatch": "/javascript/"
},
{
"text": "Algorithm",
"link": "/algorithm/markdown-examples",
"activeMatch": "/algorithm/"
},
{
"text": "Vue",
"link": "/vue/markdown-examples",
"activeMatch": "/vue/"
},
{
"text": "React",
"link": "/react/markdown-examples",
"activeMatch": "/react/"
}
],
"sidebar": {
"/javascript/": {
"base": "/javascript/",
"items": [
{
"text": "JavaScript 继承",
"link": "/js-inherit"
},
{
"text": "JavaScript 函数调用方式",
"link": "/js-function-invoke"
},
{
"text": "JavaScript Call",
"link": "/js-call"
},
{
"text": "JavaScript Apply",
"link": "/js-apply"
},
{
"text": "JavaScript Bind",
"link": "/js-bind"
},
{
"text": "JavaScript instanceof",
"link": "/js-instanceof"
},
{
"text": "JavaScript new",
"link": "/js-new"
},
{
"text": "JavaScript curry",
"link": "/js-curry"
},
{
"text": "JavaScript iterable",
"link": "/js-iterable"
},
{
"text": "JavaScript promise",
"link": "/js-promise"
}
]
},
"/algorithm/": {
"base": "/algorithm/",
"items": [
{
"text": "Markdown Examples",
"link": "/algorithm/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/algorithm/api-examples"
}
]
},
"/vue/": {
"base": "/vue/",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "ref vs reactive",
"link": "/ref-vs-reactive"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
},
"/react/": {
"base": "/react/",
"items": [
{
"text": "Markdown Examples",
"link": "/react/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/react/api-examples"
}
]
}
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
]
}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.