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": "最近在读",
      "items": [
        {
          "text": "罗振宇推荐",
          "link": "/luozhenlyu"
        },
        {
          "text": "狼图腾2",
          "items": [
            {
              "text": "狼图腾",
              "link": "/recent"
            },
            {
              "text": "狼图腾2",
              "link": "/recent1"
            }
          ]
        },
        {
          "text": "其他",
          "items": [
            {
              "text": "其他1",
              "link": "/recent2"
            },
            {
              "text": "其他2",
              "link": "/recent3"
            }
          ]
        }
      ]
    }
  ],
  "sidebar": {
    "/recent": [
      {
        "text": "最近",
        "items": [
          {
            "text": "狼图腾",
            "link": "/recent/bxEYR1zAbZMmVzK4p1oxl67XeNaB83Olnow92GJERgryYQdDnqjkPLvO5eOZ8Nqr"
          },
          {
            "text": "狼图腾2",
            "link": "/recent/bxEYR1zAbZMmVzK4p1oxl67XeNaB83Olnow92GJERgryYQdDnqjkPLvO5eOZ8Nqr"
          }
        ]
      }
    ],
    "/luozhenlyu": [
      {
        "text": "罗振宇推荐",
        "items": [
          {
            "text": "狼图腾",
            "link": "/luozhenlyu/bxEYR1zAbZMmVzK4p1oxl67XeNaB83Olnow92GJERgryYQdDnqjkPLvO5eOZ8Nqr"
          },
          {
            "text": "狼图腾2",
            "link": "/luozhenlyu/bxEYR1zAbZMmVzK4p1oxl67XeNaB83Olnow92GJERgryYQdDnqjkPLvO5eOZ8Nqr"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  },
  "returnToTopLabel": "回到顶部",
  "sidebarMenuLabel": "菜单",
  "darkModeSwitchLabel": "主题",
  "lightModeSwitchTitle": "切换到浅色模式",
  "darkModeSwitchTitle": "切换到深色模式"
}

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.