运行时 API 示例
本页演示了 VitePress 提供的一些运行时 API 的使用方法。
useData()API可用于访问当前页面的站点、主题和页面数据。它适用于.md 和 .vue文件:
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>结果
主题数据
{
"redirects": {},
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "示例",
"link": "/views/examples/markdown-examples"
}
],
"sidebar": [
{
"text": "示例",
"items": [
{
"text": "Markdown 示例",
"link": "/views/examples/markdown-examples"
},
{
"text": "API 示例",
"link": "/views/examples/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/xiaotaokh"
}
]
}页面数据
{
"title": "运行时 API 示例",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "views/examples/api-examples.md",
"filePath": "views/examples/api-examples.md"
}页面前言
{
"outline": "deep"
}More
查看文档以获取运行时 API 的完整列表。