Skip to content

About this page

Edit this page on GitHub

Last updated:

On this page

Last updated:

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": "Guide",
      "activeMatch": "^/guide/",
      "items": [
        {
          "text": "Guide",
          "items": [
            {
              "text": "Introduction",
              "link": "/guide/introduction"
            },
            {
              "text": "Getting Started",
              "link": "/guide/getting-started"
            },
            {
              "text": "Configuration",
              "link": "/guide/configuration"
            }
          ]
        },
        {
          "text": "Theme",
          "items": [
            {
              "text": "Extending",
              "link": "/guide/extending-theme"
            },
            {
              "text": "Custom Layouts",
              "link": "/guide/custom-layouts"
            },
            {
              "text": "LLM Markdown Actions",
              "link": "/guide/llm-markdown-actions"
            }
          ]
        },
        {
          "text": "Components",
          "items": [
            {
              "text": "Built-in Components",
              "link": "/guide/components"
            },
            {
              "text": "Creating Components",
              "link": "/guide/custom-components"
            },
            {
              "text": "Home",
              "link": "/guide/home-component"
            }
          ]
        }
      ]
    },
    {
      "text": "Examples",
      "activeMatch": "^/examples/",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/examples/markdown-examples"
        },
        {
          "text": "Math Equations",
          "link": "/examples/math-equations"
        },
        {
          "text": "Runtime API Examples",
          "link": "/examples/api-examples"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "Guide",
      "items": [
        {
          "text": "Introduction",
          "link": "/guide/introduction"
        },
        {
          "text": "Getting Started",
          "link": "/guide/getting-started"
        },
        {
          "text": "Configuration",
          "link": "/guide/configuration"
        }
      ]
    },
    {
      "text": "Theme",
      "items": [
        {
          "text": "Extending",
          "link": "/guide/extending-theme"
        },
        {
          "text": "Custom Layouts",
          "link": "/guide/custom-layouts"
        },
        {
          "text": "LLM Markdown Actions",
          "link": "/guide/llm-markdown-actions"
        }
      ]
    },
    {
      "text": "Components",
      "items": [
        {
          "text": "Built-in Components",
          "link": "/guide/components"
        },
        {
          "text": "Creating Components",
          "link": "/guide/custom-components"
        },
        {
          "text": "Home",
          "link": "/guide/home-component"
        }
      ]
    },
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/examples/markdown-examples"
        },
        {
          "text": "Math Equations",
          "link": "/examples/math-equations"
        },
        {
          "text": "Runtime API Examples",
          "link": "/examples/api-examples"
        }
      ]
    }
  ],
  "outline": [
    2,
    3
  ],
  "logo": {
    "src": "/logo.svg"
  },
  "search": {
    "provider": "local"
  },
  "editLink": {
    "pattern": "https://github.com/brenoepics/vitepress-carbon/edit/main/packages/demo/src/:path",
    "text": "Edit this page on GitHub"
  },
  "lastUpdated": {
    "formatOptions": {
      "dateStyle": "short",
      "timeStyle": "short"
    }
  },
  "socialLinks": [
    {
      "icon": "storybook",
      "link": "/storybook/",
      "ariaLabel": "Storybook — every Carbon component in isolation"
    },
    {
      "icon": "github",
      "link": "https://github.com/brenoepics/vitepress-carbon"
    }
  ],
  "footer": {
    "action": {
      "text": "Create Repository",
      "link": "https://github.com/new?template_name=carbon-starter&template_owner=brenoepics"
    },
    "message": "Released under the <a href=\"https://github.com/brenoepics/vitepress-carbon/blob/main/LICENSE\">MIT License</a>.",
    "copyright": "Copyright © 2024–2026 <a href=\"https://github.com/brenoepics\">Breno A.</a>"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "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": "examples/api-examples.md",
  "filePath": "examples/api-examples.md",
  "lastUpdated": 1774093013000
}

Page Frontmatter

{
  "outline": "deep"
}

More

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