Runtime API Examples
字数
142 字
阅读时间
1 分钟
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
{
"search": {
"provider": "algolia",
"options": {
"appId": "5U3NHQASVP",
"apiKey": "814bf078cb6d8c832d054fa5a8257e08",
"indexName": "ayyyyyy",
"locales": {
"root": {
"placeholder": "搜索文档",
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"searchBox": {
"resetButtonTitle": "清除查询条件",
"resetButtonAriaLabel": "清除查询条件",
"cancelButtonText": "取消",
"cancelButtonAriaLabel": "取消"
},
"startScreen": {
"recentSearchesTitle": "搜索历史",
"noRecentSearchesText": "没有搜索历史",
"saveRecentSearchButtonTitle": "保存至搜索历史",
"removeRecentSearchButtonTitle": "从搜索历史中移除",
"favoriteSearchesTitle": "收藏",
"removeFavoriteSearchButtonTitle": "从收藏中移除"
},
"errorScreen": {
"titleText": "无法获取结果",
"helpText": "你可能需要检查你的网络连接"
},
"footer": {
"selectText": "选择",
"selectKeyAriaLabel": "回车键",
"navigateText": "切换",
"navigateUpKeyAriaLabel": "向上键",
"navigateDownKeyAriaLabel": "向下键",
"closeText": "关闭",
"closeKeyAriaLabel": "Escape 键"
},
"noResultsScreen": {
"noResultsText": "无法找到相关结果",
"suggestedQueryText": "你可以尝试查询",
"reportMissingResultsText": "你认为该查询应该有结果?",
"reportMissingResultsLinkText": "点击反馈"
}
}
}
}
}
}
},
"nav": [
{
"text": "Home",
"link": "/"
},
{
"text": "Examples",
"link": "/markdown-examples"
},
{
"text": "Notes",
"link": "/notes/test"
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/vuejs/vitepress"
}
],
"editLink": {
"pattern": "https://gitlab.com/ayyyyyy/notes-vitepress/edit/main/docs/:path",
"text": "编辑本页面"
},
"sidebar": {
"/notes/test/": {
"base": "/notes/test/",
"items": [
{
"text": "测试示例",
"link": "测试示例"
},
{
"text": "脚注功能测试",
"link": "脚注功能测试"
}
]
}
}
}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.