运行时 API 示例
本页展示了 VitePress 提供的部分运行时 API 的使用方法。
主要的 useData() API 可用于获取当前页面的站点数据、主题数据和页面数据。该 API 在 .md 和 .vue 文件中均可使用:
md
<script setup>
import { useData } from 'vitepress'
const { theme, page, frontmatter } = useData()
</script>
## 结果
### 主题数据
<pre>{{ theme }}</pre>
### 页面数据
<pre>{{ page }}</pre>
### 页面Frontmatter
<pre>{{ frontmatter }}</pre>结果
主题数据
{
"logo": "/index.svg",
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "文档",
"link": "/markdown-examples"
}
],
"editLink": {
"pattern": "https://github.com/vuejs/vitepress/edit/main/docs/:path",
"text": "在GitHub上编辑此页面"
},
"sidebar": [
{
"text": "小工具",
"items": [
{
"text": "WebCipherBox",
"link": "/docx/WebCipherBox.md"
},
{
"text": "Nonsense Encryptor",
"link": "/docx/Nonsense-encryptor"
},
{
"text": "Text Encryptor",
"link": "/docx/Text-Encryptor"
},
{
"text": "WebMoyue",
"link": "/docx/WebMoyue"
}
]
},
{
"text": "示例",
"items": [
{
"text": "Markdown 示例",
"link": "/markdown-examples"
},
{
"text": "Runtime API 示例",
"link": "/api-examples"
}
]
}
],
"outlineTitle": "文章目录",
"outline": [
2,
6
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/FancyStarry/docx-demo"
},
{
"icon": {
"svg": "<svg t=\"1751175558821\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"5008\" width=\"200\" height=\"200\"><path d=\"M679.424 746.862l84.005-395.996c7.424-34.852-12.581-48.567-35.438-40.009L234.277 501.138c-33.72 13.13-33.134 32-5.706 40.558l126.282 39.424 293.156-184.576c13.714-9.143 26.295-3.986 16.018 5.157L426.898 615.973l-9.143 130.304c13.13 0 18.871-5.706 25.71-12.581l61.696-59.429 128 94.282c23.442 13.129 40.01 6.29 46.3-21.724zM1024 512c0 282.843-229.157 512-512 512S0 794.843 0 512 229.157 0 512 0s512 229.157 512 512z\" fill=\"#1296DB\" p-id=\"5009\"></path></svg>"
},
"link": "https://t.me"
}
],
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"noResultsText": "无法找到相关结果",
"resetButtonTitle": "清除查询条件",
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "取消"
}
}
}
}
},
"lastUpdated": {
"text": "最后更新于",
"formatOptions": {
"dateStyle": "full",
"timeStyle": "medium"
}
},
"docFooter": {
"prev": "上一页",
"next": "下一页"
},
"lightModeSwitchTitle": "切换到浅色模式",
"darkModeSwitchTitle": "切换到深色模式",
"returnToTopLabel": "回到顶部",
"externalLinkIcon": true
}页面数据
{
"title": "运行时 API 示例",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1751180822000
}页面Frontmatter
{
"outline": "deep"
}更多
查看文档以获取完整的运行时API列表.