Skip to content
On this page

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": "/logo.svg",
  "nav": [
    {
      "text": "Guide",
      "link": "/core-concepts/",
      "activeMatch": "^/core-concepts/"
    },
    {
      "text": "API",
      "link": "/api/",
      "activeMatch": "^/api/"
    }
  ],
  "sidebar": {
    "/": [
      {
        "text": "Introduction",
        "items": [
          {
            "text": "What is KValidator?",
            "link": "/introduction.html"
          },
          {
            "text": "Getting Started",
            "link": "/getting-started.html"
          }
        ]
      },
      {
        "text": "Core Concepts",
        "items": [
          {
            "text": "Defining a validator",
            "link": "/core-concepts/"
          },
          {
            "text": "Custom constraint",
            "link": "/core-concepts/"
          },
          {
            "text": "Internationalization",
            "link": "/core-concepts/"
          },
          {
            "text": "SelfValidating data classes",
            "link": "/core-concepts/"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/knusperleicht/kvalidator"
    }
  ],
  "footer": {
    "copyright": "Copyright © 2023 KNUSPERLEICHT DEVELOPMENT OG",
    "message": "Released under the MIT License."
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api/index.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.