运行时API文稿
本页面演示了VitePress提供的一些运行时API的用法。
主要的useData() API可用于访问当前页面的站点、主题和页面数据。它可以在.md和.vue文件中使用:
md
<script setup>
import { useData } from 'vitepress'
const { theme, page, frontmatter } = useData()
</script>
## 结果
### 主题数据
<pre>{{ theme }}</pre>
### 页面数据
<pre>{{ page }}</pre>
### 页面前置元数据
<pre>{{ frontmatter }}</pre>结果
主题数据
{
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "文稿",
"link": "/official-examples/markdown-articles"
}
],
"sidebar": [
{
"text": "文稿",
"items": [
{
"text": "官方示例",
"items": [
{
"text": "Markdown文稿",
"link": "/official-examples/markdown-articles"
},
{
"text": "运行时API文稿",
"link": "/official-examples/api-articles"
}
]
},
{
"text": "Linux 30年",
"items": [
{
"text": "被嘲笑是\"黑客玩具\"?Linux是如何在微软和UNIX的夹缝中逆天改命的?",
"link": "/linux-30-years/linux-history"
}
]
},
{
"text": "EndevaourOS 适中化设置",
"link": "/articles/endeavouros-moderate-setup"
},
{
"text": "CachyOS 安装初始化脚本",
"link": "/articles/cachyos-install-script"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://gitcode.com/ozhouliren"
},
{
"icon": "bilibili",
"link": "https://space.bilibili.com/51420401"
},
{
"icon": "wechat",
"link": "#",
"ariaLabel": "公众号"
}
],
"editLink": {
"pattern": "https://github.com/izhouliren/kyqn/edit/main/:path",
"text": "在 GitHub 上编辑此页"
}
}页面数据
{
"title": "运行时API文稿",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "official-examples/api-articles.md",
"filePath": "official-examples/api-articles.md"
}页面前置元数据
{
"outline": "deep"
}更多
查看完整的运行时API列表文档。