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

{
  "siteTitle": "ZenChyn",
  "logo": "/zenchyn.png",
  "outline": {
    "level": [
      2,
      3
    ],
    "label": "页面导航"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "指南",
      "items": [
        {
          "text": "介绍",
          "link": "/zenchyn"
        },
        {
          "text": "快速开始",
          "link": "/start"
        },
        {
          "text": "更新日志",
          "link": "/download"
        },
        {
          "text": "接口文档",
          "link": "https://doc.zenchyn.com/"
        },
        {
          "text": "常见问题",
          "link": "/faq"
        }
      ]
    },
    {
      "text": "🥤一杯咖啡",
      "link": "/thanks"
    },
    {
      "text": "官方论坛",
      "link": "https://bbs.zenchyn.com/"
    }
  ],
  "footer": {
    "message": "<a target=\"_blank\" rel=\"noopener\" href=\"https://beian.miit.gov.cn/\">鄂ICP备2022006206号</a>",
    "copyright": "Copyright © 2025-云程"
  },
  "sidebar": {
    "/zenchyn": [
      {
        "items": [
          {
            "text": "介绍",
            "link": "/zenchyn"
          },
          {
            "text": "快速开始",
            "link": "/start"
          },
          {
            "text": "更新日志",
            "link": "/download"
          },
          {
            "text": "常见问题",
            "link": "/faq"
          }
        ]
      }
    ],
    "/start": [
      {
        "items": [
          {
            "text": "介绍",
            "link": "/zenchyn"
          },
          {
            "text": "快速开始",
            "link": "/start"
          },
          {
            "text": "更新日志",
            "link": "/download"
          },
          {
            "text": "常见问题",
            "link": "/faq"
          }
        ]
      }
    ],
    "/download": [
      {
        "items": [
          {
            "text": "介绍",
            "link": "/zenchyn"
          },
          {
            "text": "快速开始",
            "link": "/start"
          },
          {
            "text": "更新日志",
            "link": "/download"
          },
          {
            "text": "常见问题",
            "link": "/faq"
          }
        ]
      }
    ],
    "/faq": [
      {
        "items": [
          {
            "text": "介绍",
            "link": "/zenchyn"
          },
          {
            "text": "快速开始",
            "link": "/start"
          },
          {
            "text": "更新日志",
            "link": "/download"
          },
          {
            "text": "常见问题",
            "link": "/faq"
          }
        ]
      }
    ],
    "/thanks": [
      {
        "text": "🥤一杯咖啡",
        "items": [
          {
            "text": "榜上有名",
            "link": "/thanks"
          },
          {
            "text": "成为赞助者",
            "link": "/sponsor"
          }
        ]
      }
    ],
    "/sponsor": [
      {
        "text": "🥤一杯咖啡",
        "items": [
          {
            "text": "榜上有名",
            "link": "/thanks"
          },
          {
            "text": "成为赞助者",
            "link": "/sponsor"
          }
        ]
      }
    ]
  },
  "search": {
    "provider": "local"
  }
}

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.