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

{
  "search": {
    "provider": "local"
  },
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "采购",
      "link": "/采购"
    },
    {
      "text": "易经",
      "link": "/易经"
    },
    {
      "text": "真理",
      "link": "/真理"
    },
    {
      "text": "语录",
      "link": "/语录"
    },
    {
      "text": "网站样式",
      "link": "/网站样式"
    },
    {
      "text": "我的导航",
      "link": "/nav"
    },
    {
      "text": "快捷键",
      "link": "/快捷键"
    },
    {
      "text": "解决办法",
      "link": "/解决办法"
    },
    {
      "text": "命令",
      "link": "/命令"
    },
    {
      "text": "工具",
      "link": "/工具"
    },
    {
      "text": "关于",
      "link": "/关于"
    }
  ],
  "sidebar": [],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2025-present Rubyc 备案号:<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">皖ICP备16003804号</a>"
  },
  "socialLinks": [],
  "darkModeSwitchLabel": "深浅模式",
  "sidebarMenuLabel": "目录",
  "returnToTopLabel": "返回顶部",
  "editLink": {
    "pattern": "https://github.com/rubyyc/rubyc-blog/blob/main/docs/:path",
    "text": "在GitHub编辑本页"
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  }
}

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.