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": "/2025/6月/07:第一篇博客"
    },
    {
      "text": "关于我",
      "link": "/about"
    },
    {
      "text": "示例页面",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "2025",
      "collapsible": true,
      "collapsed": false,
      "items": [
        {
          "text": "6月",
          "collapsible": true,
          "collapsed": false,
          "items": [
            {
              "text": "07:什么是最优质的资产",
              "link": "2025/6月/07:什么是最优质的资产.md"
            },
            {
              "text": "07:第一篇博客",
              "link": "2025/6月/07:第一篇博客.md"
            },
            {
              "text": "10:什么是最重要的能力",
              "link": "2025/6月/10:什么是最重要的能力.md"
            },
            {
              "text": "13:房地产未来走势路线",
              "link": "2025/6月/13:房地产未来走势路线.md"
            },
            {
              "text": "15:2025年6月的最重要的事情",
              "link": "2025/6月/15:2025年6月的最重要的事情.md"
            },
            {
              "text": "18:房地产即将加速下跌",
              "link": "2025/6月/18:房地产即将加速下跌.md"
            },
            {
              "text": "25:2018年才是经济的顶点",
              "link": "2025/6月/25:2018年才是经济的顶点.md"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/xuzhijian24"
    },
    {
      "icon": "gitee",
      "link": "https://gitee.com/xuxiaoxie"
    }
  ]
}

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.