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

{}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "title": "Runtime API Examples",
    "excerpt": "Demonstrates usage of VitePress runtime APIs like useData().",
    "image": "https://images.unsplash.com/photo-1577864662891-c7b77f10f638?q=80&w=2070&auto=format&fit=crop",
    "createdAt": "2025-04-26T00:00:00.000Z",
    "updatedAt": "2025-04-27T00:00:00.000Z"
  },
  "headers": [
    {
      "level": 2,
      "title": "Results",
      "slug": "results",
      "link": "#results",
      "children": [
        {
          "level": 3,
          "title": "Theme Data",
          "slug": "theme-data",
          "link": "#theme-data",
          "children": []
        },
        {
          "level": 3,
          "title": "Page Data",
          "slug": "page-data",
          "link": "#page-data",
          "children": []
        },
        {
          "level": 3,
          "title": "Page Frontmatter",
          "slug": "page-frontmatter",
          "link": "#page-frontmatter",
          "children": []
        }
      ]
    },
    {
      "level": 2,
      "title": "More",
      "slug": "more",
      "link": "#more",
      "children": []
    }
  ],
  "relativePath": "blogs/api-examples.md",
  "filePath": "blogs/api-examples.md"
}

Page Frontmatter

{
  "title": "Runtime API Examples",
  "excerpt": "Demonstrates usage of VitePress runtime APIs like useData().",
  "image": "https://images.unsplash.com/photo-1577864662891-c7b77f10f638?q=80&w=2070&auto=format&fit=crop",
  "createdAt": "2025-04-26T00:00:00.000Z",
  "updatedAt": "2025-04-27T00:00:00.000Z"
}

More

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