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": "/images/jiaoliu.svg",
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "Golang",
      "link": "/go/nats"
    },
    {
      "text": "VOIP文档",
      "link": "/voip/freeswitch"
    },
    {
      "text": "Python文档",
      "link": "/python/snownlp情感分析"
    }
  ],
  "sidebar": {
    "/go/": [
      {
        "text": "常用库使用",
        "items": [
          {
            "text": "多线程库",
            "items": [
              {
                "text": "ants",
                "link": "/go/ants"
              }
            ]
          },
          {
            "text": "消息队列",
            "items": [
              {
                "text": "nats",
                "link": "/go/nats"
              },
              {
                "text": "nsq",
                "link": "/go/nsq"
              }
            ]
          },
          {
            "text": "数据库",
            "items": [
              {
                "text": "zincsearch",
                "link": "/go/zincsearch"
              }
            ]
          },
          {
            "text": "其他库",
            "items": [
              {
                "text": "qqzengphone",
                "link": "/go/qqzengphone"
              },
              {
                "text": "sonic",
                "link": "/go/sonic"
              }
            ]
          }
        ]
      }
    ],
    "/voip/": [
      {
        "text": "VOIP文档",
        "items": [
          {
            "text": "freeswitch",
            "items": [
              {
                "text": "技术文档",
                "link": "/voip/freeswitch"
              }
            ]
          },
          {
            "text": "kamailio",
            "items": [
              {
                "text": "技术文档",
                "link": "/voip/kamailio"
              }
            ]
          }
        ]
      }
    ],
    "/python/": [
      {
        "text": "Python文档",
        "items": [
          {
            "text": "snownlp情感分析",
            "link": "/python/snownlp情感分析"
          }
        ]
      }
    ]
  },
  "lastUpdated": true,
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "outline": {
    "label": "页面导航"
  },
  "search": {
    "provider": "local"
  },
  "footer": {
    "copyright": "Copyright © 2026 Heckman <a style=\"text-decoration: none;\" href=\"https://beian.miit.gov.cn/\" target=\"_blank\">鄂ICP备2021012826号-2</a>"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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