技法详解
此页展示 VitePress 提供的部分运行时 API 用法。
核心 API useData() 可用于访问当前页面的站点数据、主题数据和页面数据,适用于 .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>结果
主题数据
{
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "笔墨",
"link": "/markdown-examples"
},
{
"text": "技法",
"link": "/api-examples"
}
],
"sidebar": [
{
"text": "文章",
"items": [
{
"text": "笔墨文章",
"link": "/markdown-examples"
},
{
"text": "技法详解",
"link": "/api-examples"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/TayeShi"
}
],
"footer": {
"message": "今年新梦,忽到水经旧山头",
"copyright": "见她依旧笑如花"
},
"outline": {
"label": "目录"
},
"docFooter": {
"prev": "上一篇",
"next": "下一篇"
},
"lastUpdated": {
"text": "最后更新"
},
"returnToTopLabel": "回到顶部",
"sidebarMenuLabel": "菜单",
"darkModeSwitchLabel": "深色模式"
}页面数据
{
"title": "技法详解",
"description": "",
"frontmatter": {
"outline": "deep"
},
"headers": [],
"relativePath": "api-examples.md",
"filePath": "api-examples.md",
"lastUpdated": 1779087473000
}页面 Frontmatter
{
"outline": "deep"
}更多
查阅文档了解 完整的运行时 API 列表。