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": "示例",
      "link": "/markdown-examples"
    },
    {
      "text": "前端",
      "link": "/code/Front-side/"
    },
    {
      "text": "后端",
      "link": "/code/Server-side/"
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "text": "搜索",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "title": "搜索",
          "noResults": "没有结果",
          "noResultsText": "没有找到匹配的结果",
          "resetButtonTitle": "清除搜索",
          "footer": {
            "selectText": "选择",
            "navigateText": "切换"
          }
        }
      }
    }
  },
  "sidebar": {
    "/code/Front-side": [
      {
        "text": "CSS",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Front-side/CSS/index.md"
          }
        ]
      },
      {
        "text": "HTML",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Front-side/HTML/index.md"
          }
        ]
      },
      {
        "text": "JavaScript",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Front-side/JavaScript/index.md"
          }
        ]
      },
      {
        "text": "TypeScript",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Front-side/TypeScript/index.md"
          }
        ]
      },
      {
        "text": "git",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Front-side/git/index.md"
          }
        ]
      }
    ],
    "/code/Server-side": [
      {
        "text": "Cpp",
        "collapsible": true,
        "items": [
          {
            "text": "cmake基础",
            "link": "/code/Server-side/Cpp/cmake基础.md"
          },
          {
            "text": "index",
            "link": "/code/Server-side/Cpp/index.md"
          },
          {
            "text": "photo",
            "collapsible": true,
            "items": []
          },
          {
            "text": "杂项",
            "collapsible": true,
            "items": [
              {
                "text": "调用第三方库",
                "link": "/code/Server-side/Cpp/杂项/调用第三方库.md"
              }
            ]
          }
        ]
      },
      {
        "text": "Java",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Server-side/Java/index.md"
          },
          {
            "text": "基础",
            "collapsible": true,
            "items": [
              {
                "text": "基本日期操作",
                "link": "/code/Server-side/Java/基础/基本日期操作.md"
              }
            ]
          },
          {
            "text": "网络编程",
            "collapsible": true,
            "items": [
              {
                "text": "UDP通信",
                "link": "/code/Server-side/Java/网络编程/UDP通信.md"
              }
            ]
          }
        ]
      }
    ],
    "/code/Server-side/Cpp/": [
      {
        "text": "cmake基础",
        "link": "/code/Server-side/Cpp/cmake基础.md"
      },
      {
        "text": "photo",
        "collapsible": true,
        "items": []
      },
      {
        "text": "杂项",
        "collapsible": true,
        "items": [
          {
            "text": "调用第三方库",
            "link": "/code/Server-side/Cpp/杂项/调用第三方库.md"
          }
        ]
      }
    ],
    "/code/Server-side/Java/": [
      {
        "text": "基础",
        "collapsible": true,
        "items": [
          {
            "text": "基本日期操作",
            "link": "/code/Server-side/Java/基础/基本日期操作.md"
          }
        ]
      },
      {
        "text": "网络编程",
        "collapsible": true,
        "items": [
          {
            "text": "UDP通信",
            "link": "/code/Server-side/Java/网络编程/UDP通信.md"
          }
        ]
      }
    ],
    "/code/Algorithm/": [
      {
        "text": "STL常用函数",
        "collapsible": true,
        "items": [
          {
            "text": "index",
            "link": "/code/Algorithm/STL常用函数/index.md"
          },
          {
            "text": "删除移除函数",
            "link": "/code/Algorithm/STL常用函数/删除移除函数.md"
          },
          {
            "text": "排序函数",
            "link": "/code/Algorithm/STL常用函数/排序函数.md"
          },
          {
            "text": "查找函数",
            "link": "/code/Algorithm/STL常用函数/查找函数.md"
          }
        ]
      }
    ]
  },
  "outline": {
    "level": "deep",
    "label": "页面目录"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/2839448514/code_book"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2025-present 2839448514@qq.com"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Last updated:

Released under the MIT License.