Skip to content

运行时 API 示例 ​

更新: 8/9/2026 字数: 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>

结果 ​

主题数据 ​

{
  "logo": "/logo.jpg",
  "nav": [
    {
      "text": "1.临时",
      "link": "/1.临时/"
    },
    {
      "text": "2.工作",
      "link": "/2.工作/"
    },
    {
      "text": "3.编程",
      "link": "/3.编程/"
    },
    {
      "text": "4.生信",
      "link": "/4.生信/"
    },
    {
      "text": "5.测序",
      "link": "/5.测序/"
    },
    {
      "text": "6.装机",
      "link": "/6.装机/"
    },
    {
      "text": "7.进阶",
      "link": "/7.进阶/"
    }
  ],
  "sidebar": {
    "/1.临时/": [
      {
        "text": "1.临时",
        "link": "/1.临时/",
        "items": []
      }
    ],
    "/2.工作/": [
      {
        "text": "2.工作",
        "link": "/2.工作/",
        "items": []
      }
    ],
    "/3.编程/": [
      {
        "text": "3.编程",
        "link": "/3.编程/",
        "items": []
      }
    ],
    "/4.生信/": [
      {
        "text": "4.生信",
        "link": "/4.生信/",
        "items": []
      }
    ],
    "/5.测序/": [
      {
        "text": "5.测序",
        "link": "/5.测序/",
        "items": []
      }
    ],
    "/6.装机/": [
      {
        "text": "6.装机",
        "link": "/6.装机/",
        "items": []
      }
    ],
    "/7.进阶/": [
      {
        "text": "7.进阶",
        "link": "/7.进阶/",
        "items": []
      }
    ]
  },
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "medium"
    }
  },
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  },
  "darkModeSwitchLabel": "切换主题",
  "sidebarMenuLabel": "菜单",
  "returnToTopLabel": "返回顶部",
  "footer": {
    "message": "这是页面底部信息",
    "copyright": "Copyright © 2019-2026 ccoc.cc"
  },
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "resetButtonTitle": "清除查询条件",
          "resetButtonAriaLabel": "清除查询条件",
          "cancelButtonText": "取消",
          "cancelButtonAriaLabel": "取消",
          "startScreen": {
            "recentSearchesTitle": "搜索历史",
            "noRecentSearchesText": "没有搜索历史",
            "saveRecentSearchButtonTitle": "保存至搜索历史",
            "removeRecentSearchButtonTitle": "从搜索历史中移除",
            "favoriteSearchesTitle": "收藏",
            "removeFavoriteSearchButtonTitle": "从收藏中移除"
          },
          "errorScreen": {
            "titleText": "无法获取结果",
            "helpText": "你可能需要检查你的网络连接"
          },
          "footer": {
            "selectText": "选择",
            "navigateText": "切换",
            "closeText": "关闭"
          },
          "noResultsScreen": {
            "noResultsText": "无法找到相关结果",
            "suggestedQueryText": "你可以尝试查询",
            "reportMissingResultsText": "你认为该查询应该有结果?",
            "reportMissingResultsLinkText": "点击反馈"
          }
        }
      },
      "miniSearch": {
        "options": {
          "searchOptions": {
            "boost": {
              "title": 4,
              "text": 1
            }
          }
        }
      }
    }
  },
  "notFound": {
    "title": "页面未找到",
    "quote": "哎呀,您好像迷失在网络的小胡同里啦,别着急,赶紧回头是岸!",
    "linkText": "返回首页"
  }
}

页面数据 ​

{
  "title": "运行时 API 示例",
  "description": "",
  "frontmatter": {
    "0": "大",
    "1": "纲",
    "2": ":",
    "3": "深",
    "4": "度"
  },
  "headers": [],
  "relativePath": "00_示例/api-examples.md",
  "filePath": "00_示例/api-examples.md",
  "lastUpdated": 1786282209000
}

页面前置信息 ​

{
  "0": "大",
  "1": "纲",
  "2": ":",
  "3": "深",
  "4": "度"
}

更多内容 ​

请查阅 完整的运行时 API 列表 的文档。

最后更新于:

这是页面底部信息