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.svg",
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "项目",
      "link": "/projects/"
    },
    {
      "text": "研究笔记",
      "link": "/notes/"
    },
    {
      "text": "开发日志",
      "link": "/logs/"
    },
    {
      "text": "关于",
      "link": "/about"
    }
  ],
  "sidebar": {
    "/projects/mai-pico/": [
      {
        "text": "Mai Pico",
        "items": [
          {
            "text": "项目概览",
            "link": "/projects/mai-pico/"
          },
          {
            "text": "硬件设计",
            "link": "/projects/mai-pico/hardware"
          },
          {
            "text": "固件结构",
            "link": "/projects/mai-pico/firmware"
          },
          {
            "text": "输入延迟分析",
            "link": "/projects/mai-pico/latency-analysis"
          }
        ]
      }
    ],
    "/notes/": [
      {
        "text": "研究笔记",
        "items": [
          {
            "text": "笔记索引",
            "link": "/notes/"
          },
          {
            "text": "嵌入式系统",
            "link": "/notes/embedded/"
          },
          {
            "text": "机械设计",
            "link": "/notes/mechanical/"
          }
        ]
      }
    ]
  },
  "search": {
    "provider": "local"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/Timsuo"
    }
  ],
  "lastUpdated": {
    "text": "最后更新于"
  },
  "outline": {
    "label": "本页目录",
    "level": [
      2,
      3
    ]
  },
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  },
  "footer": {
    "message": "内容以研究记录和项目文档为主",
    "copyright": "Copyright © 2026 Timsuo"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

最后更新于:

内容以研究记录和项目文档为主