Skip to content

运行时 API 示例

更新: 12/18/2025 字数: 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>

结果

主题数据

{
  "sidebarMenuLabel": "菜单",
  "outlineTitle": "页面内容",
  "darkModeSwitchLabel": "切换主题",
  "editLink": {
    "pattern": "https://github.com/StarryCognet/AToolkit/edit/main/docs/:path",
    "text": "在GitHub编辑本页"
  },
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "medium"
    }
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "教程",
      "link": "/使用教程"
    },
    {
      "text": "目录",
      "link": "/目录"
    },
    {
      "text": "博客",
      "link": "https://starrymiku.com"
    },
    {
      "text": "工具分类",
      "items": [
        {
          "text": "系统工具",
          "link": "/tools/系统工具"
        },
        {
          "text": "硬件检测与优化",
          "link": "/tools/硬件检测与优化"
        },
        {
          "text": "磁盘管理与清理",
          "link": "/tools/磁盘管理与清理"
        },
        {
          "text": "文件管理",
          "link": "/tools/文件管理"
        },
        {
          "text": "压缩与格式转换",
          "link": "/tools/压缩与格式转换"
        },
        {
          "text": "多媒体处理",
          "link": "/tools/多媒体处理"
        },
        {
          "text": "截图与演示",
          "link": "/tools/截图与演示"
        },
        {
          "text": "网络工具",
          "link": "/tools/网络工具"
        },
        {
          "text": "安全与卸载",
          "link": "/tools/安全与卸载"
        },
        {
          "text": "游戏相关",
          "link": "/tools/游戏相关"
        },
        {
          "text": "效率与时间管理",
          "link": "/tools/效率与时间管理"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "catalogue",
      "items": [
        {
          "text": "Electron入门笔记",
          "link": "/catalogue/Electron入门笔记"
        },
        {
          "text": "运行时API示例",
          "link": "/catalogue/运行时API示例"
        }
      ],
      "collapsed": false
    },
    {
      "text": "tools",
      "items": [
        {
          "text": "压缩与格式转换",
          "link": "/tools/压缩与格式转换"
        },
        {
          "text": "多媒体处理",
          "link": "/tools/多媒体处理"
        },
        {
          "text": "安全与卸载",
          "link": "/tools/安全与卸载"
        },
        {
          "text": "截图与演示",
          "link": "/tools/截图与演示"
        },
        {
          "text": "效率与时间管理",
          "link": "/tools/效率与时间管理"
        },
        {
          "text": "文件管理",
          "link": "/tools/文件管理"
        },
        {
          "text": "游戏相关",
          "link": "/tools/游戏相关"
        },
        {
          "text": "硬件检测与优化",
          "link": "/tools/硬件检测与优化"
        },
        {
          "text": "磁盘管理与清理",
          "link": "/tools/磁盘管理与清理"
        },
        {
          "text": "系统工具",
          "link": "/tools/系统工具"
        },
        {
          "text": "网络工具",
          "link": "/tools/网络工具"
        }
      ],
      "collapsed": false
    },
    {
      "text": "使用教程",
      "link": "/使用教程"
    },
    {
      "text": "目录",
      "link": "/目录"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/StarryCognet/AToolkit"
    }
  ]
}

页面数据

{
  "title": "运行时 API 示例",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "catalogue/运行时API示例.md",
  "filePath": "catalogue/运行时API示例.md",
  "lastUpdated": 1766060681000
}

页面前置元数据

{
  "outline": "deep"
}

更多内容

查看文档了解 运行时 API 完整列表