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
{
"logo": "/favicon.png",
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"displayDetails": "显示详情",
"resetButtonTitle": "重置搜索",
"backButtonTitle": "关闭",
"noResultsText": "没有找到相关结果",
"footer": {
"selectText": "选择",
"selectKeyAriaLabel": "回车",
"navigateText": "切换",
"navigateUpKeyAriaLabel": "上箭头",
"navigateDownKeyAriaLabel": "下箭头",
"closeText": "关闭",
"closeKeyAriaLabel": "Esc"
}
}
}
}
},
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/PersonalViolet/violet-agents"
}
],
"footer": {
"message": "基于 MIT 许可发布 <br/> <a href=\"https://beian.miit.gov.cn/\" target=\"_blank\" rel=\"noopener noreferrer\">粤ICP备2026080692号</a>",
"copyright": "Copyright © 2024 Violet Agents"
},
"lastUpdated": {
"text": "Last updated"
},
"nav": [
{
"text": "Guide",
"link": "/en/guide/introduction"
},
{
"text": "Examples",
"link": "/en/examples/markdown"
}
],
"sidebar": {
"/en/guide/": [
{
"text": "Guide",
"collapsed": false,
"items": [
{
"text": "Getting Started",
"link": "/en/guide/getting-started"
},
{
"text": "Introduction",
"link": "/en/guide/introduction"
}
]
}
],
"/en/examples/": [
{
"text": "Examples",
"collapsed": false,
"items": [
{
"text": "Markdown Examples",
"link": "/en/examples/markdown"
},
{
"text": "API Examples",
"link": "/en/examples/api"
}
]
}
],
"/en/": []
},
"outline": {
"label": "On this page",
"level": [
2,
3
]
},
"docFooter": {
"prev": "Previous page",
"next": "Next page"
},
"darkModeSwitchLabel": "Appearance",
"sidebarMenuLabel": "Menu",
"returnToTopLabel": "Return to top"
}Page Data
{
"title": "API Examples",
"description": "",
"frontmatter": {},
"headers": [],
"relativePath": "en/examples/api.md",
"filePath": "en/examples/api.md",
"lastUpdated": 1783870309000
}Page Frontmatter
{}More
Check out the documentation for the full list of runtime APIs.