运行时 API 示例
更新: Invalid Date 字数: 0 字 时长: 0 分钟
本页面演示了如何使用 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": "/markdown-examples"
},
{
"text": "目录",
"link": "/catalogue/"
}
],
"sidebar": [
{
"text": "示例",
"items": [
{
"text": "Markdown 示例",
"link": "/markdown-examples"
},
{
"text": "运行时 API 示例",
"link": "/api-examples"
}
]
},
{
"text": "目录",
"items": [
{
"text": "Markdown 示例",
"link": "/catalogue/tools"
},
{
"text": "Electron入门笔记",
"link": "/catalogue/Electron入门笔记"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/StarryCognet/AToolkit"
}
]
}页面数据
{
"title": "运行时 API 示例",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md"
}页面前置元数据
{
"outline": "deep"
}更多内容
查看文档了解 运行时 API 完整列表。