运行时 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>
### 页面 Frontmatter
<pre>{{ frontmatter }}</pre>结果
主题数据
展开
{
"logo": "/images/index/logo.svg",
"search": {
"provider": "local",
"options": {
"translations": {
"button": {
"buttonText": "搜索文档",
"buttonAriaLabel": "搜索文档"
},
"modal": {
"noResultsText": "未找到结果",
"resetButtonTitle": "清除查询条件",
"displayDetails": "切换详细信息",
"footer": {
"selectText": "选择",
"navigateText": "切换",
"closeText": "关闭"
}
}
}
}
},
"nav": [
{
"text": "首页",
"link": "/"
},
{
"text": "文章",
"link": "/blog/"
},
{
"text": "指南",
"link": "/guide/"
}
],
"lightModeSwitchTitle": "切换至亮色模式",
"darkModeSwitchTitle": "切换至深色模式",
"darkModeSwitchLabel": "切换明暗模式",
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/will961123/vitepress-doc"
}
],
"sidebar": {
"/guide": {
"text": "指南",
"link": "/guide",
"items": [
{
"text": "搭建指南",
"items": [
{
"text": "vitepress 搭建指南",
"link": "/guide/搭建指南/vitepress 搭建指南"
}
]
},
{
"text": "官方示例",
"items": [
{
"text": "Markdown 扩展示例",
"link": "/guide/官方示例/Markdown 扩展示例"
},
{
"text": "运行时 API 示例",
"link": "/guide/官方示例/运行时 API 示例"
}
]
}
]
},
"/blog": {
"text": "文章",
"link": "/blog",
"items": [
{
"text": "杂谈",
"collapsed": false,
"items": [
{
"text": "windows 常用软件",
"link": "/blog/杂谈/windows 常用软件"
},
{
"text": "powershell 增强",
"link": "/blog/杂谈/powershell 增强"
},
{
"text": "告别密码输入:SSH 密钥配置 GitHub/Gitee/GitLab",
"link": "/blog/杂谈/告别密码输入:SSH 密钥配置 GitHub_Gitee_GitLab"
},
{
"text": "解决 Cloudflare Pages 的 Yarn 版本冲突问题",
"link": "/blog/杂谈/解决 Cloudflare Pages 的 Yarn 版本冲突问题"
},
{
"text": "解决 Cloudflare Pages 部署 VitePress 时最后更新时间异常问题",
"link": "/blog/杂谈/解决 Cloudflare Pages 部署 VitePress 时最后更新时间异常问题"
}
]
},
{
"text": "jetbrains",
"collapsed": false,
"items": [
{
"text": "jetbrains 远程开发",
"link": "/blog/jetbrains/jetbrains 远程开发"
}
]
},
{
"text": "docker",
"collapsed": false,
"items": [
{
"text": "windows11 家庭版安装 Docker Desktop",
"link": "/blog/docker/windows11 家庭版安装 Docker Desktop"
}
]
},
{
"text": "linux",
"collapsed": false,
"items": [
{
"text": "zsh 安装及美化",
"link": "/blog/linux/zsh 安装及美化"
}
]
}
]
}
},
"sidebarMenuLabel": "目录",
"outline": {
"label": "文章大纲",
"level": [
2,
3
]
},
"returnToTopLabel": "返回顶部",
"editLink": {
"pattern": "https://github.com/will961123/vitepress-doc/edit/main/src/:path",
"text": "在GitHub编辑本页"
},
"lastUpdated": {
"text": "最后更新于",
"formatOptions": {
"dateStyle": "short",
"timeStyle": "medium"
}
},
"docFooter": {
"prev": "上一页",
"next": "下一页"
},
"footer": {
"message": "本站总访问量 <span id=\"busuanzi_value_site_pv\">--</span> 次",
"copyright": "Released under the MIT License. Copyright© 2024 wpf"
}
}页面数据
展开
{
"title": "运行时 API 示例",
"description": "",
"frontmatter": {},
"headers": [],
"relativePath": "guide/官方示例/运行时 API 示例.md",
"filePath": "guide/官方示例/运行时 API 示例.md",
"lastUpdated": 1725523827000
}页面 Frontmatter
展开
{}更多
查看文档以获取 完整的运行时 API 列表。