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

{
  "logo": "/icon.png",
  "darkModeSwitchLabel": "切换主题",
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "outlineTitle": "页面内容",
  "returnToTopLabel": "返回顶部",
  "sidebarMenuLabel": "菜单",
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "noResultsText": "无法找到相关结果",
          "resetButtonTitle": "清除查询条件",
          "footer": {
            "selectText": "选择",
            "navigateText": "切换",
            "closeText": "关闭"
          }
        }
      }
    }
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "文档",
      "link": "/docs/markdown-examples"
    },
    {
      "text": "关于",
      "items": [
        {
          "text": "sitemap",
          "link": "/sitemap.xml"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "快速上手",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/docs/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/docs/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/fhowotop/MirageMC"
    }
  ],
  "editLink": {
    "pattern": "https://github.com/fhowotop/MirageMC/edit/main/:path",
    "text": "在GitHub编辑本页"
  },
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "medium"
    }
  },
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2025-present <a href=\"https://github.com/fhowotop/MirageMC\">MirageMC</a>"
  },
  "notFound": {
    "quote": "如果方向不变,继续前行,你可能会到达所想象的终点✨",
    "linkText": "返回首页"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.