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

{
  "footer": {
    "message": "FORT WIRE<br>MCG GLOBAL PTY LTD",
    "copyright": "ABN: 50 610 489 775"
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Pipe Hangers & Supports",
      "link": "/markdown-examples"
    },
    {
      "text": "PIPE",
      "items": [
        {
          "text": "Item A",
          "items": [
            {
              "text": "1",
              "link": "/item-1"
            },
            {
              "text": "2",
              "link": "/item-2"
            },
            {
              "text": "3",
              "link": "/item-3"
            }
          ]
        },
        {
          "text": "Item B",
          "link": "/item-2"
        },
        {
          "text": "Item C",
          "link": "/item-3"
        }
      ]
    },
    {
      "text": "PIPE",
      "items": [
        {
          "text": "Item A",
          "link": "/item-1"
        },
        {
          "text": "Item B",
          "link": "/item-2"
        },
        {
          "text": "Item C",
          "link": "/item-3"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "Pipe Hangers & Supports",
      "items": [
        {
          "text": "Beam Clamps",
          "collapsed": true,
          "link": "/beam-clamps",
          "items": [
            {
              "text": "Clevis Hangers",
              "link": "/clevis-hangers"
            },
            {
              "text": "New Version",
              "link": "/clevis-hangers2"
            },
            {
              "text": "v3nocss",
              "link": "/clevis-hangers3"
            },
            {
              "text": "Clevis Hangers",
              "link": "/api-examples3"
            }
          ]
        },
        {
          "text": "Clevis Hangers",
          "collapsed": true,
          "link": "/api-examples",
          "items": [
            {
              "text": "Clevis Hangers",
              "link": "/api-examples4"
            },
            {
              "text": "Clevis Hangers",
              "link": "/api-examples5"
            },
            {
              "text": "Clevis Hangers",
              "link": "/api-examples6"
            },
            {
              "text": "Clevis Hangers",
              "link": "/api-examples7"
            }
          ]
        },
        {
          "text": "Swivel Ring Hangers",
          "collapsed": true,
          "link": "/steel-beam-clamp"
        },
        {
          "text": "Pipe and Riser Clamps",
          "link": "/markdown-examples"
        },
        {
          "text": "CPVC Clamps",
          "link": "/markdown-examples"
        },
        {
          "text": "THREADED ACCESSORIES ",
          "link": "/markdown-examples"
        },
        {
          "text": "ATTACHMENTS",
          "link": "/markdown-examples"
        },
        {
          "text": "PIPE STAYS AND STRAPS",
          "link": "/markdown-examples"
        },
        {
          "text": "PIPE ROLLER SUPPORTS",
          "link": "/markdown-examples"
        },
        {
          "text": "EPDM RUBBER LINED CLAMPS",
          "link": "/markdown-examples"
        },
        {
          "text": "MISCELLANEOUS PRODUCTS",
          "link": "/markdown-examples"
        },
        {
          "text": "TECHNICAL DATA",
          "link": "/markdown-examples"
        }
      ]
    },
    {
      "text": "Strut Channels & Fittings",
      "items": [
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "BC Beam Clamp",
          "link": "/api-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        },
        {
          "text": "Universal Beam Clamp",
          "link": "/markdown-examples"
        }
      ]
    }
  ],
  "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.

FORT WIRE
MCG GLOBAL PTY LTD