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

{
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "说明",
      "link": "/introduction"
    }
  ],
  "sidebar": [
    {
      "text": "主页面",
      "items": [
        {
          "text": "说明",
          "link": "/introduction"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    },
    {
      "text": "2025-08",
      "items": [
        {
          "text": "VitePress 设置中文",
          "link": "/2025-08/vitepress-chinese"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/Bluevect"
    }
  ],
  "darkModeSwitchLabel": "切换外观",
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  },
  "outlineTitle": "大纲",
  "returnToTopLabel": "返回顶部",
  "sidebarMenuLabel": "菜单",
  "notFound": {
    "title": "页面未找到",
    "quote": "但也许不改变航向,持续航行,也能到达你要去的彼岸 ",
    "linkText": "返回首页"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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