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": "/logo.jpg",
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "组件库",
      "link": "/components"
    },
    {
      "text": "Hooks",
      "link": "/components"
    },
    {
      "text": "Utils",
      "link": "/components"
    },
    {
      "text": "专栏",
      "items": [
        {
          "text": "人工智能",
          "link": "/columns/ai"
        }
      ]
    }
  ],
  "outline": 3,
  "sidebar": {
    "/interview/": [
      {
        "text": "JavaScript",
        "items": [
          {
            "text": "变量类型",
            "link": "/interview/javascript/variable-type"
          },
          {
            "text": "内置函数",
            "link": "/interview/javascript/built-in-function"
          },
          {
            "text": "变量作用域",
            "link": "/interview/javascript/variable-scope"
          },
          {
            "text": "对象",
            "link": "/interview/javascript/object"
          },
          {
            "text": "数组",
            "link": "/interview/javascript/array"
          },
          {
            "text": "原型和原型链",
            "link": "/interview/javascript/prototype"
          },
          {
            "text": "内存泄漏",
            "link": "/interview/javascript/closure-leak"
          },
          {
            "text": "函数",
            "link": "/interview/javascript/function"
          },
          {
            "text": "this",
            "link": "/interview/javascript/this"
          },
          {
            "text": "严格模式",
            "link": "/interview/javascript/strict-mode"
          },
          {
            "text": "存储",
            "link": "/interview/javascript/web-storage"
          }
        ]
      },
      {
        "text": "Vue",
        "items": [
          {
            "text": "选项",
            "link": "/interview/vue/options"
          },
          {
            "text": "Key值",
            "link": "/interview/vue/key"
          },
          {
            "text": "MVVM",
            "link": "/interview/vue/mvvm"
          },
          {
            "text": "数据劫持",
            "link": "/interview/vue/reactive"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/CodeEvlstan/blog"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2025-present Evlstan"
  }
}

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.

Released under the MIT License.