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": "Home",
      "link": "/"
    },
    {
      "text": "Start Reading",
      "link": "/Chapter-00"
    },
    {
      "text": "v0.0.1",
      "link": "/changelog"
    }
  ],
  "sidebar": [
    {
      "text": "Prologue",
      "items": [
        {
          "text": "Chapter 0: Dimensional Shard & The Probe",
          "link": "/Chapter-00"
        }
      ]
    },
    {
      "text": "Volume I: The Monolith Illusion",
      "collapsed": false,
      "items": [
        {
          "text": "Chapter 1: The Crimson Vines of the Super Bowl",
          "link": "/Chapter-01"
        },
        {
          "text": "Chapter 2: The Amnesiac Behemoth",
          "link": "/Chapter-02"
        },
        {
          "text": "Chapter 3: The War of Locks",
          "link": "/Chapter-03"
        },
        {
          "text": "Chapter 4: The Phantom Write",
          "link": "/Chapter-04"
        },
        {
          "text": "Chapter 5: The Funeral of the B+ Tree",
          "link": "/Chapter-05"
        },
        {
          "text": "Chapter 6: The Silicon Valley Blackout",
          "link": "/Chapter-06"
        },
        {
          "text": "Chapter 7: The Birth of Multi-Active",
          "link": "/Chapter-07"
        },
        {
          "text": "Chapter 8: The Exile of State",
          "link": "/Chapter-08"
        },
        {
          "text": "Chapter 9: The Suffocation of the Connection Pool",
          "link": "/Chapter-09"
        },
        {
          "text": "Chapter 10: The End of the Monolith",
          "link": "/Chapter-10"
        }
      ]
    },
    {
      "text": "Volume II: The Distributed Swamp",
      "collapsed": false,
      "items": [
        {
          "text": "Chapter 11: The Dawn of Microservices",
          "link": "/Chapter-11"
        },
        {
          "text": "Chapter 12: The Cache Stampede Zombie Horde",
          "link": "/Chapter-12"
        },
        {
          "text": "Chapter 13: Split-Brain & the Double-Write Tear",
          "link": "/Chapter-13"
        },
        {
          "text": "Chapter 14: The Poison of the Message Queue",
          "link": "/Chapter-14"
        },
        {
          "text": "Chapter 15: The Retry Storm Echo Chamber",
          "link": "/Chapter-15"
        },
        {
          "text": "Chapter 16: Cardinality Explosion",
          "link": "/Chapter-16"
        },
        {
          "text": "Chapter 17: The Macro Fan-Out Storm",
          "link": "/Chapter-17"
        },
        {
          "text": "Chapter 18: The Curse of the Platform",
          "link": "/Chapter-18"
        },
        {
          "text": "Chapter 19: Conway's Law Iron Fist",
          "link": "/Chapter-19"
        },
        {
          "text": "Chapter 20: The Endgame of Distribution",
          "link": "/Chapter-20"
        }
      ]
    },
    {
      "text": "Volume III: The Planetary Isolation Cell",
      "collapsed": false,
      "items": [
        {
          "text": "Chapter 21: The GDPR Iron Curtain & Physical Enclaves",
          "link": "/Chapter-21"
        },
        {
          "text": "Chapter 22: BGP Anycast Stateless Routing",
          "link": "/Chapter-22"
        },
        {
          "text": "Chapter 23: Shuffle Sharding Bulletproof Vest",
          "link": "/Chapter-23"
        },
        {
          "text": "Chapter 24: TrueTime Atomic Clock",
          "link": "/Chapter-24"
        },
        {
          "text": "Chapter 25: The Cell Matrix Takes Shape",
          "link": "/Chapter-25"
        },
        {
          "text": "Chapter 26: The BMC Backdoor Lurks",
          "link": "/Chapter-26"
        },
        {
          "text": "Chapter 27: The Genesis Crypto Block",
          "link": "/Chapter-27"
        },
        {
          "text": "Chapter 28: UPS Damping Neutralized",
          "link": "/Chapter-28"
        },
        {
          "text": "Chapter 29: The Crustal Antenna Activates",
          "link": "/Chapter-29"
        },
        {
          "text": "Chapter 30: Hello World",
          "link": "/Chapter-30"
        }
      ]
    }
  ],
  "docFooter": {
    "prev": "Previous Chapter",
    "next": "Next Chapter"
  },
  "outline": {
    "label": "On this page"
  },
  "sidebarMenuLabel": "Chapters",
  "returnToTopLabel": "Back to top",
  "darkModeSwitchLabel": "Appearance",
  "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"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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