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": "japanese",
      "link": "/contents/japanese/"
    },
    {
      "text": "nya",
      "link": "/contents/nya/"
    }
  ],
  "sidebar": {
    "/contents/japanese/": [
      {
        "text": "japanese",
        "items": [
          {
            "text": "简介",
            "link": "/contents/japanese/"
          },
          {
            "text": "第一章",
            "link": "/contents/japanese/chapter1"
          }
        ]
      }
    ],
    "/contents/nya/": [
      {
        "text": "nya",
        "items": [
          {
            "text": "简介",
            "link": "/contents/nya/"
          },
          {
            "text": "第一章",
            "link": "/contents/nya/chapter1"
          }
        ]
      }
    ]
  },
  "footer": {
    "message": "\n        <span style=\"display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 12px; color: var(--vp-c-text-2);\">\n          <span style=\"flex: 1; text-align: left;\">\n            © 2026 natsuki\n          </span>\n          <span style=\"flex: 2; text-align: center;\">\n            本作品原创内容采用<a href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\" target=\"_blank\" rel=\"license noopener noreferrer\">CC BY-NC-SA 4.0</a>许可,引用内容版权归原权利人所有\n          </span>\n          <span style=\"flex: 1; text-align: right;\">\n            <a href=\"https://about.natsuki.cloud\" target=\"_blank\">关于奈月</a>\n          </span>\n        </span>\n      "
  },
  "search": {
    "provider": "local"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "contents/nya/index.md",
  "filePath": "contents/nya/index.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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