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
{
"logo": "/images/logo.png",
"siteTitle": "Hello World",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "VitePress",
"link": "https://vitepress.dev/"
},
{
"text": "1.0.0-rc.**",
"items": [
{
"text": "更新日志",
"link": "https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md"
},
{
"text": "贡献",
"link": "https://github.com/vuejs/vitepress/blob/main/.github/contributing.md"
}
]
}
],
"sidebar": [
{
"text": "Examples",
"items": [
{
"text": "Markdown Examples",
"link": "/markdown-examples"
},
{
"text": "Runtime API Examples",
"link": "/api-examples"
}
]
}
],
"lastUpdated": {
"text": "最后更新于",
"formatOptions": {
"dateStyle": "short",
"timeStyle": "medium"
}
},
"outline": {
"level": [
2,
4
],
"label": "当前页大纲"
},
"docFooter": {
"prev": "上一篇",
"next": "下一篇"
},
"darkModeSwitchLabel": "切换主题",
"outlineTitle": "页面内容",
"returnToTopLabel": "返回顶部",
"sidebarMenuLabel": "菜单",
"search": {
"provider": "local",
"options": {
"placeholder": "搜索文档",
"translations": {
"button": {
"buttonText": "搜索文档"
},
"modal": {
"searchBox": {
"resetButtonTitle": "清除查询条件",
"cancelButtonText": "取消"
},
"startScreen": {
"recentSearchesTitle": "搜索历史",
"noRecentSearchesText": "没有搜索历史"
},
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭"
},
"noResultsScreen": {
"noResultsText": "无法找到相关结果"
}
}
}
}
},
"notFound": {
"title": "页面未找到",
"quote": "哎呀,您好像迷失在网络的小胡同里啦,别着急,赶紧回头是岸!",
"linkText": "返回首页"
},
"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",
"lastUpdated": null
}Page Frontmatter
{
"outline": "deep"
}More
Check out the documentation for the full list of runtime APIs.
更新时间: 1970/1/1 08:00:00
