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": "Home",
      "link": "/"
    },
    {
      "text": "指南",
      "link": "/guide/installation"
    },
    {
      "text": "组件",
      "link": "/component/"
    }
  ],
  "sidebar": {
    "/guide/": [
      {
        "text": "基础指南",
        "items": [
          {
            "text": "安装",
            "link": "/guide/installation"
          },
          {
            "text": "主题",
            "link": "/guide/theming"
          },
          {
            "text": "快速开始",
            "link": "/guide/quickstart"
          },
          {
            "text": "更新日志",
            "link": "/guide/changelog"
          }
        ]
      }
    ],
    "/component/": [
      {
        "text": "Element Plus 基础组件",
        "items": [
          {
            "text": "Basic 基础组件",
            "items": [
              {
                "text": "Button 按钮",
                "link": "/component/basic/button.md"
              },
              {
                "text": "Border 边框",
                "link": "/component/basic/border.md"
              },
              {
                "text": "Color 色彩",
                "link": "/component/basic/color.md"
              },
              {
                "text": "Container 布局容器",
                "link": "/component/basic/container.md"
              }
            ]
          },
          {
            "text": "配置组件",
            "items": [
              {
                "text": "Config Provider 全局配置",
                "link": "/component/basic/button.md"
              }
            ]
          }
        ]
      },
      {
        "text": "Pro 版扩展组件",
        "items": [
          {
            "text": "ProButtonGroup 按钮组",
            "link": "/component/pro/pro-button-group"
          },
          {
            "text": "ProSelect 下拉框",
            "link": "/component/pro/pro-select"
          },
          {
            "text": "ProRadioGroup 单选框组",
            "link": "/component/pro/pro-radio-group"
          },
          {
            "text": "ProCheckboxGroup 多选框组",
            "link": "/component/pro/pro-checkbox-group"
          },
          {
            "text": "Runtime API Examples",
            "link": "/api-examples"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

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.