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
{
"outline": {
"level": [
1,
3
]
},
"nav": [
{
"text": "Home",
"link": "/"
},
{
"text": "Quick Start",
"link": "/quick-start/quick-start"
},
{
"text": "Examples",
"link": "/examples/markdown-examples"
}
],
"sidebar": [
{
"text": "网站管理",
"collapsed": true,
"items": [
{
"text": "Overview",
"link": "/quick-start/quick-start"
},
{
"text": "Installation",
"link": "/quick-start/quick-start#installation"
},
{
"text": "Basic Setup",
"link": "/quick-start/quick-start#basic-setup"
},
{
"text": "Configuration",
"link": "/quick-start/quick-start#configuration"
}
]
},
{
"text": "四层转发",
"collapsed": true,
"items": [
{
"text": "Custom Theme",
"link": "/advanced/custom-theme"
},
{
"text": "Markdown Extensions",
"link": "/advanced/markdown-extensions"
},
{
"text": "Code Highlighting",
"link": "/advanced/code-highlighting"
}
]
},
{
"text": "Deployment",
"collapsed": true,
"items": [
{
"text": "Build for Production",
"link": "/quick-start/quick-start#build-for-production"
},
{
"text": "GitHub Pages",
"link": "/quick-start/quick-start#deploy-to-github-pages"
},
{
"text": "Netlify",
"link": "/quick-start/quick-start#netlify-deployment"
}
]
},
{
"text": "Examples",
"items": [
{
"text": "Markdown Examples",
"link": "/examples/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/examples/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/TencentEdgeOne/pages-templates/tree/main/examples/vitepress-template"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "examples/api-examples.md",
"filePath": "examples/api-examples.md"
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.