Skip to content

Runtime API Examples

团子简单

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

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>

Results

Theme Data

{
  "darkModeSwitchLabel": "切换主题",
  "outlineTitle": "页面内容",
  "returnToTopLabel": "返回顶部",
  "sidebarMenuLabel": "菜单",
  "nav": [],
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  },
  "lastUpdated": {
    "text": "最后更新于"
  },
  "editLink": {
    "pattern": "https://gitee.com/kuaifuzhi/simple-doc/edit/master/docs/:path",
    "text": "在 GitHub 上编辑此页面"
  },
  "search": {
    "provider": "algolia",
    "options": {
      "appId": "TP15H205XD",
      "apiKey": "ac483df4d6a0a7d8b9cb26fa077d5360",
      "indexName": "Simple",
      "placeholder": "搜索笔记",
      "translations": {
        "button": {
          "buttonText": "搜索文档"
        },
        "modal": {
          "noResultsText": "无法找到相关结果",
          "resetButtonTitle": "清除查询条件",
          "searchBox": {
            "resetButtonTitle": "清除查询条件",
            "resetButtonAriaLabel": "清除查询条件",
            "cancelButtonText": "取消",
            "cancelButtonAriaLabel": "取消"
          },
          "startScreen": {
            "recentSearchesTitle": "搜索历史",
            "noRecentSearchesText": "没有搜索历史",
            "saveRecentSearchButtonTitle": "保存至搜索历史",
            "removeRecentSearchButtonTitle": "从搜索历史中移除",
            "favoriteSearchesTitle": "收藏",
            "removeFavoriteSearchButtonTitle": "从收藏中移除"
          },
          "errorScreen": {
            "titleText": "无法获取结果",
            "helpText": "你可能需要检查你的网络连接"
          },
          "footer": {
            "selectText": "选择",
            "navigateText": "切换",
            "closeText": "关闭",
            "searchByText": "搜索提供者"
          },
          "noResultsScreen": {
            "noResultsText": "无法找到相关结果",
            "suggestedQueryText": "你可以尝试查询",
            "reportMissingResultsText": "你认为该查询应该有结果?",
            "reportMissingResultsLinkText": "点击反馈"
          }
        }
      }
    }
  },
  "sidebar": [
    {
      "text": "api-examples",
      "link": "/api-examples"
    },
    {
      "text": "markdown-examples",
      "link": "/markdown-examples"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "notFound": {
    "title": "页面未找到",
    "quote": "哎呀,您好像迷失在网络的小胡同里啦,别着急,赶紧回头是岸!",
    "linkText": "返回首页"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1766240134000
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.