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": "Clients",
      "link": "/clients/"
    },
    {
      "text": "FIR",
      "link": "/fir/"
    },
    {
      "text": "Teamwork",
      "link": "/teamwork/"
    },
    {
      "text": "External Services",
      "link": "/external-services/"
    },
    {
      "text": "Dev Setup",
      "link": "/dev-setup"
    }
  ],
  "sidebar": [
    {
      "text": "Fir Theme Framework",
      "items": [
        {
          "text": "Overview",
          "link": "/fir/"
        }
      ]
    },
    {
      "text": "Teamwork & Collaboration",
      "items": [
        {
          "text": "Overview",
          "link": "/teamwork/"
        }
      ]
    },
    {
      "text": "External Services",
      "items": [
        {
          "text": "Overview",
          "link": "/external-services/"
        }
      ]
    },
    {
      "text": "Dev Setup",
      "items": [
        {
          "text": "Development Environment",
          "link": "/dev-setup"
        },
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    },
    {
      "text": "Clients",
      "items": [
        {
          "text": "Overview",
          "link": "/clients/"
        },
        {
          "text": "Accurate Lock & Hardware",
          "link": "/clients/accurate-lock-hardware",
          "items": [
            {
              "text": "AccurateLockAndHardware.com",
              "link": "/clients/accurate-lock-hardware/accuratelockandhardware"
            },
            {
              "text": "AccessByAccurate.com",
              "link": "/clients/accurate-lock-hardware/accessbyaccurate"
            }
          ]
        },
        {
          "text": "Arriston",
          "link": "/clients/arriston"
        },
        {
          "text": "CHB Foundation",
          "link": "/clients/chb-foundation",
          "items": [
            {
              "text": "CHBFoundation.com",
              "link": "/clients/chb-foundation/chbfoundation"
            }
          ]
        },
        {
          "text": "CoSign",
          "link": "/clients/cosign",
          "items": [
            {
              "text": "CoSign.Agency",
              "link": "/clients/cosign/cosign-agency"
            }
          ]
        },
        {
          "text": "EBAD",
          "link": "/clients/ebad"
        },
        {
          "text": "Fortina Pizza",
          "link": "/clients/fortina-pizza"
        },
        {
          "text": "Horizon Kinetics",
          "link": "/clients/horizon-kinetics",
          "items": [
            {
              "text": "ConsensusMining.com",
              "link": "/clients/horizon-kinetics/consensusmining"
            },
            {
              "text": "HKHoldingCo.com",
              "link": "/clients/horizon-kinetics/hkholdingco"
            },
            {
              "text": "HorizonKinetics.com",
              "link": "/clients/horizon-kinetics/horizonkinetics"
            },
            {
              "text": "KineticsFunds.com",
              "link": "/clients/horizon-kinetics/kineticsfunds"
            },
            {
              "text": "Wealth-Index.com",
              "link": "/clients/horizon-kinetics/wealth-index"
            }
          ]
        },
        {
          "text": "Hopes",
          "link": "/clients/hopes"
        },
        {
          "text": "illumynt",
          "link": "/clients/illumynt"
        },
        {
          "text": "JetFuel Studios",
          "link": "/clients/jetfuel-studios"
        },
        {
          "text": "Mr Showerdoor",
          "link": "/clients/mr-showerdoor"
        },
        {
          "text": "Munger Construction",
          "link": "/clients/munger-construction"
        },
        {
          "text": "Piesanos",
          "link": "/clients/piesanos",
          "items": [
            {
              "text": "PiesanosToGo.com",
              "link": "/clients/piesanos/piesanostogo"
            }
          ]
        },
        {
          "text": "Gators Dockside",
          "link": "/clients/gators-dockside"
        },
        {
          "text": "Rebod",
          "link": "/clients/rebod"
        },
        {
          "text": "Response",
          "link": "/clients/response",
          "items": [
            {
              "text": "Portal.Response.Hosting",
              "link": "/clients/response/portal-response-hosting"
            },
            {
              "text": "Response.Agency",
              "link": "/clients/response/response-agency"
            }
          ]
        },
        {
          "text": "Sally's Pizza",
          "link": "/clients/sallys-pizza",
          "items": [
            {
              "text": "SallysaPizza.com",
              "link": "/clients/sallys-pizza/sallysapizza"
            }
          ]
        },
        {
          "text": "Sikorsky",
          "link": "/clients/sikorsky"
        }
      ]
    }
  ],
  "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.