Skip to content

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

useData

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": "/images/logo.svg",
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "指南",
      "link": "/guides/site"
    },
    {
      "text": "示例",
      "link": "/examples/markdown-examples"
    },
    {
      "text": "考试",
      "items": [
        {
          "text": "二〇二五",
          "link": "/exams/"
        }
      ]
    }
  ],
  "sidebar": {
    "/examples/": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/examples/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/examples/api-examples"
          }
        ]
      }
    ],
    "/guides/": [
      {
        "text": "Guides",
        "items": [
          {
            "text": "Tool Site",
            "link": "/guides/site"
          },
          {
            "text": "Public DNS",
            "link": "/guides/dns"
          }
        ]
      }
    ],
    "/exams/": [
      {
        "text": "Exams",
        "items": [
          {
            "text": "二〇二五",
            "link": "/exams/#二〇二五"
          }
        ]
      }
    ]
  },
  "outline": {
    "label": "页面导航"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/fanghsiu"
    },
    {
      "icon": "gitlab",
      "link": "https://gitlab.com/fanghsiu"
    },
    {
      "icon": {
        "svg": "<span class=\"vpi-social-blog\" style=\"--icon: url('https://api.iconify.design/fa6-solid:blog.svg');\"></span>"
      },
      "link": "https://www.fanghsiu.top"
    }
  ],
  "footer": {
    "message": "基于 MIT 许可发布",
    "copyright": "版权所有 © 方脩"
  },
  "editLink": {
    "pattern": "https://github.com/fanghsiu/wiki/edit/main/docs/:path",
    "text": "在 GitHub 上编辑此页面"
  },
  "lastUpdated": {
    "text": "最后更新于"
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "search": {
    "provider": "local"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

基于 MIT 许可发布