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": "/icon.png",
  "siteTitle": "Hello World",
  "lastUpdated": {
    "text": "最后更新于",
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "medium"
    }
  },
  "search": {
    "provider": "local"
  },
  "nav": [
    {
      "text": "三国演义",
      "link": "/三国演义/三国演义-上卷/宴桃园豪杰三结义",
      "activeMatch": "/三国演义"
    },
    {
      "text": "链接",
      "items": [
        {
          "text": "GitHub仓库",
          "link": "https://github.com/ockerm698-coder"
        }
      ]
    }
  ],
  "sidebar": {
    "/三国演义/": [
      {
        "text": "三国演义-上卷",
        "items": [
          {
            "text": "宴桃园豪杰三结义",
            "link": "/三国演义/三国演义-上卷/宴桃园豪杰三结义"
          },
          {
            "text": "张翼德怒鞭督邮",
            "link": "/三国演义/三国演义-上卷/张翼德怒鞭督邮"
          }
        ],
        "collapsed": false
      },
      {
        "text": "三国演义-下卷",
        "items": [
          {
            "text": "三江口曹操折兵",
            "link": "/三国演义/三国演义-下卷/三江口曹操折兵"
          },
          {
            "text": "用奇谋孔明借箭",
            "link": "/三国演义/三国演义-下卷/用奇谋孔明借箭"
          }
        ],
        "collapsed": false
      }
    ]
  },
  "outlineTitle": "页面导航",
  "outline": "deep",
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  },
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2025-2025 Ockerm"
  },
  "returnToTopLabel": "返回顶部",
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

最后更新于:

Released under the MIT License.