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

{
  "outlineTitle": "本页内容",
  "outline": [
    2,
    6
  ],
  "logo": "/logo.png",
  "search": {
    "provider": "local",
    "options": {
      "placeholder": "🔍 搜点技术试试...",
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "noResultsText": "无法找到相关结果",
          "resetButtonTitle": "清除查询条件",
          "footer": {
            "selectText": "选择",
            "navigateText": "切换"
          }
        }
      }
    }
  },
  "nav": [
    {
      "text": "前端",
      "items": [
        {
          "text": "html",
          "link": "/front-end/html/"
        },
        {
          "text": "css",
          "link": "/front-end/css/"
        },
        {
          "text": "javascript",
          "link": "/front-end/javascript/"
        },
        {
          "text": "vue",
          "link": "/front-end/vue/"
        },
        {
          "text": "react",
          "link": "/front-end/react/"
        }
      ]
    },
    {
      "text": "后端",
      "items": [
        {
          "text": "java",
          "link": "/back-end/java/"
        },
        {
          "text": "mysql",
          "link": "/back-end/mysql/"
        },
        {
          "text": "redis",
          "link": "/back-end/redis/"
        },
        {
          "text": "spring",
          "link": "/back-end/spring/"
        }
      ]
    },
    {
      "text": "AI",
      "items": [
        {
          "text": "Python",
          "link": "/AI/Python/"
        },
        {
          "text": "AI应用",
          "link": "/AI/applications/"
        }
      ]
    }
  ],
  "sidebar": {
    "/front-end/html/": [
      {
        "text": "reac是什么",
        "link": "front-end/html/reac是什么"
      }
    ],
    "/AI/Python/": [
      {
        "text": "01-Python核心语法-数据存储与运算",
        "link": "AI/Python/01-Python核心语法-数据存储与运算"
      },
      {
        "text": "02-Python核心语法-流程控制语句",
        "link": "AI/Python/02-Python核心语法-流程控制语句"
      },
      {
        "text": "03-Python核心语法-数据存储容器",
        "link": "AI/Python/03-Python核心语法-数据存储容器"
      },
      {
        "text": "04-Python核心语法-函数",
        "link": "AI/Python/04-Python核心语法-函数"
      },
      {
        "text": "05-Python核心语法-模块",
        "link": "AI/Python/05-Python核心语法-模块"
      },
      {
        "text": "06-Python核心语法-面向对象与异常",
        "link": "AI/Python/06-Python核心语法-面向对象与异常"
      },
      {
        "text": "07-网络基础知识",
        "link": "AI/Python/07-网络基础知识"
      },
      {
        "text": "08-panda数据matplotlib数据视图",
        "link": "AI/Python/08-panda数据matplotlib数据视图"
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/adventurer002"
    }
  ],
  "footer": {
    "copyright": "Copyright © WangEdgar2026"
  }
}

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.