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

![logo.jpg](../public/logo.jpg)

<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": "/logo.svg",
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "关于我们",
      "link": "/us/about"
    },
    {
      "text": "产品中心",
      "link": "/product/markdown-examples"
    },
    {
      "text": "技术能力",
      "link": "/tech/ability"
    }
  ],
  "sidebar": [
    {
      "text": "产品系列",
      "items": [
        {
          "text": "产品A",
          "link": "/product/markdown-examples"
        },
        {
          "text": "产品B",
          "link": "/product/api-examples"
        },
        {
          "text": "型号C",
          "link": "/product/model-a01"
        },
        {
          "text": "型号D",
          "link": "/product/model-a02"
        },
        {
          "text": "型号E",
          "link": "/product/model-a03"
        }
      ]
    }
  ],
  "search": {
    "provider": "local"
  },
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2026-present(可放网站备案号) "
  },
  "darkModeSwitch": true
}

Page Data ​

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

Page Frontmatter ​

{
  "outline": "deep"
}

More ​

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

Released under the MIT License.