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": "/logo.svg",
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "快速开始",
      "link": "/guide/getting-started"
    },
    {
      "text": "API 文档",
      "link": "/api/"
    }
  ],
  "sidebar": [
    {
      "text": "使用指南",
      "items": [
        {
          "text": "快速开始",
          "link": "/guide/getting-started"
        },
        {
          "text": "项目结构",
          "link": "/guide/project-structure"
        }
      ]
    },
    {
      "text": "API 文档",
      "items": [
        {
          "text": "API 总览",
          "link": "/api/"
        },
        {
          "text": "示例代码",
          "link": "/api/api-examples"
        }
      ]
    }
  ],
  "outline": {
    "label": "本页目录~"
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "search": {
    "provider": "local"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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