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": "/grow"
    },
    {
      "text": "技术杂记",
      "link": "/vue"
    },
    {
      "text": "更多",
      "items": [
        {
          "text": "Markdown 示例",
          "link": "/markdown-examples"
        },
        {
          "text": "API 示例",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "学习笔记",
      "items": [
        {
          "text": "成长心得",
          "link": "/grow"
        },
        {
          "text": "技术杂记",
          "link": "/vue"
        }
      ]
    },
    {
      "text": "示例",
      "items": [
        {
          "text": "Markdown 示例",
          "link": "/markdown-examples"
        },
        {
          "text": "API 示例",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "search": {
    "provider": "local"
  },
  "editLink": {
    "pattern": "",
    "text": ""
  },
  "footer": {
    "message": "备案号:<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">陇ICP备2025023208号-1</a>",
    "copyright": "Copyright © 2025 CoderJy"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "returnToTopLabel": "返回顶部",
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "medium"
    }
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "outline": {
    "label": "页面导航",
    "level": [
      2,
      3
    ]
  }
}

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.