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

{
  "logo": {
    "src": "/favicon.svg",
    "width": 24,
    "height": 24
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/phantompower82"
    },
    {
      "icon": {
        "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"128\" height=\"128\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M5.721 0C2.251 0 0 2.25 0 5.719V18.28C0 21.751 2.252 24 5.721 24h12.56C21.751 24 24 21.75 24 18.281V5.72C24 2.249 21.75 0 18.281 0zm1.964 4.078q-.408 1.096-.68 2.11h4.587c.545-.006.445 1.168.445 1.171H9.384a58 58 0 0 1-.112 3.797h2.712c.388.023.393 1.251.393 1.266H9.183a9.2 9.2 0 0 1-.408 2.102l.757-.604c.452.456 1.512 1.712 1.906 2.177c.473.681.063 2.081.063 2.081l-2.794-3.382c-.653 2.518-1.845 3.607-1.845 3.607c-.523.468-1.58.82-2.64.516c2.218-1.73 3.44-3.917 3.667-6.497H4.491c0-.015.197-1.243.806-1.266h2.71c.024-.32.086-3.254.086-3.797H6.598c-.136.406-.158.447-.268.753c-.594 1.095-1.603 1.122-1.907 1.155c.906-1.821 1.416-3.6 1.591-4.064c.425-1.124 1.671-1.125 1.671-1.125M13.078 6h6.377v11.33h-2.573l-2.184 1.373l-.401-1.373h-1.219zm1.313 1.219v8.86h.623l.263.937l1.455-.938h1.456v-8.86z\"/></svg>"
      },
      "link": "https://www.zhihu.com/people/phantom-power-82"
    }
  ],
  "nav": [
    {
      "text": "Guide",
      "link": "/guide/what-is-vitepress",
      "activeMatch": "/guide/"
    },
    {
      "text": "Reference",
      "link": "/reference/site-config",
      "activeMatch": "/reference/"
    },
    {
      "items": [
        {
          "text": "Changelog",
          "link": "https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md"
        },
        {
          "text": "Contributing",
          "link": "https://github.com/vuejs/vitepress/blob/main/.github/contributing.md"
        }
      ]
    }
  ],
  "sidebar": {
    "/guide/": {
      "base": "/guide/",
      "items": [
        {
          "text": "Introduction",
          "collapsed": false,
          "items": [
            {
              "text": "What is VitePress?",
              "link": "what-is-vitepress"
            },
            {
              "text": "Getting Started",
              "link": "getting-started"
            },
            {
              "text": "Routing",
              "link": "routing"
            },
            {
              "text": "Deploy",
              "link": "deploy"
            }
          ]
        },
        {
          "text": "Writing",
          "collapsed": false,
          "items": [
            {
              "text": "Markdown Extensions",
              "link": "markdown"
            },
            {
              "text": "Asset Handling",
              "link": "asset-handling"
            },
            {
              "text": "Frontmatter",
              "link": "frontmatter"
            },
            {
              "text": "Using Vue in Markdown",
              "link": "using-vue"
            },
            {
              "text": "Internationalization",
              "link": "i18n"
            }
          ]
        },
        {
          "text": "Customization",
          "collapsed": false,
          "items": [
            {
              "text": "Using a Custom Theme",
              "link": "custom-theme"
            },
            {
              "text": "Extending the Default Theme",
              "link": "extending-default-theme"
            },
            {
              "text": "Build-Time Data Loading",
              "link": "data-loading"
            },
            {
              "text": "SSR Compatibility",
              "link": "ssr-compat"
            },
            {
              "text": "Connecting to a CMS",
              "link": "cms"
            }
          ]
        },
        {
          "text": "Experimental",
          "collapsed": false,
          "items": [
            {
              "text": "MPA Mode",
              "link": "mpa-mode"
            },
            {
              "text": "Sitemap Generation",
              "link": "sitemap-generation"
            }
          ]
        },
        {
          "text": "Config & API Reference",
          "base": "/reference/",
          "link": "site-config"
        }
      ]
    },
    "/reference/": {
      "base": "/reference/",
      "items": [
        {
          "text": "Reference",
          "items": [
            {
              "text": "Site Config",
              "link": "site-config"
            },
            {
              "text": "Frontmatter Config",
              "link": "frontmatter-config"
            },
            {
              "text": "Runtime API",
              "link": "runtime-api"
            },
            {
              "text": "CLI",
              "link": "cli"
            },
            {
              "text": "Default Theme",
              "base": "/reference/default-theme-",
              "items": [
                {
                  "text": "Overview",
                  "link": "config"
                },
                {
                  "text": "Nav",
                  "link": "nav"
                },
                {
                  "text": "Sidebar",
                  "link": "sidebar"
                },
                {
                  "text": "Home Page",
                  "link": "home-page"
                },
                {
                  "text": "Footer",
                  "link": "footer"
                },
                {
                  "text": "Layout",
                  "link": "layout"
                },
                {
                  "text": "Badge",
                  "link": "badge"
                },
                {
                  "text": "Team Page",
                  "link": "team-page"
                },
                {
                  "text": "Prev / Next Links",
                  "link": "prev-next-links"
                },
                {
                  "text": "Edit Link",
                  "link": "edit-link"
                },
                {
                  "text": "Last Updated Timestamp",
                  "link": "last-updated"
                },
                {
                  "text": "Search",
                  "link": "search"
                },
                {
                  "text": "Carbon Ads",
                  "link": "carbon-ads"
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "footer": {}
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1726407306000
}

Page Frontmatter

{
  "outline": "deep"
}

More

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

Last updated: