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": "Notes",
      "link": "/notes"
    },
    {
      "text": "Examples",
      "link": "/examples/markdown-examples"
    }
  ],
  "sidebar": {
    "/notes/": [
      {
        "text": "Notes",
        "items": [
          {
            "text": "导读",
            "link": "/notes"
          },
          {
            "text": "考研数学",
            "collapsed": false,
            "link": "/notes/math",
            "items": [
              {
                "text": "高等数学",
                "collapsed": true,
                "link": "/notes/math/advanced-mathematics/",
                "items": [
                  {
                    "text": "映射",
                    "link": "/notes/math/advanced-mathematics/mapping"
                  },
                  {
                    "text": "函数的定义和性质",
                    "link": "/notes/math/advanced-mathematics/definition-of-function"
                  },
                  {
                    "text": "反函数和复合函数",
                    "link": "/notes/math/advanced-mathematics/supplementary-of-function"
                  },
                  {
                    "text": "初等函数",
                    "link": "/notes/math/advanced-mathematics/elementary-function"
                  }
                ]
              },
              {
                "text": "线性代数",
                "collapsed": true,
                "link": "/notes/math/linear-algebra/",
                "items": []
              },
              {
                "text": "概率论与数理统计",
                "collapsed": true,
                "link": "/notes/math/probability/",
                "items": []
              }
            ]
          },
          {
            "text": "考研408",
            "collapsed": false,
            "link": "/notes/408",
            "items": [
              {
                "text": "数据结构",
                "collapsed": true,
                "link": "/notes/408/data-structure",
                "items": [
                  {
                    "text": "数据结构基本概念",
                    "link": "/notes/408/data-structure/basic-concept-of-data-structures"
                  },
                  {
                    "text": "算法基本概念",
                    "link": "/notes/408/data-structure/basic-concepts-of-algorithms"
                  },
                  {
                    "text": "时间复杂度",
                    "link": "/notes/408/data-structure/time-complexity"
                  },
                  {
                    "text": "空间复杂度",
                    "link": "/notes/408/data-structure/spatial-complexity"
                  },
                  {
                    "text": "线性表",
                    "link": "/notes/408/data-structure/linear-list"
                  }
                ]
              },
              {
                "text": "计算机组成原理",
                "collapsed": true,
                "link": "/notes/408/computer-organization",
                "items": []
              },
              {
                "text": "操作系统",
                "collapsed": true,
                "link": "/notes/408/operating-system",
                "items": []
              },
              {
                "text": "计算机网络",
                "collapsed": true,
                "link": "/notes/408/computer-network",
                "items": []
              }
            ]
          }
        ]
      }
    ],
    "/examples/": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/examples/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/examples/api-examples"
          },
          {
            "text": "Mermaid Examples",
            "link": "/examples/mermaid-example"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/jesspig/11408-notes"
    },
    {
      "icon": "cloudflarepages",
      "link": "https://11408-notes.jesspig.site"
    }
  ],
  "outline": {
    "level": [
      2,
      6
    ],
    "label": "页内导航"
  },
  "search": {
    "provider": "local"
  },
  "footer": {
    "copyright": "Copyright © 2025-present <a href=\"https://github.com/jesspig\">JessPig</a>"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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