Sustena

Sustenas Webpräsenz

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 { site, theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

### Site Data
<pre>{{ site }}</pre>

Results

Theme Data

{
  "nav": [
    {
      "text": "Test",
      "link": "/test/",
      "items": [
        {
          "text": "API",
          "link": "/test/api-examples"
        },
        {
          "text": "Markdown",
          "link": "/test/markdown-examples"
        }
      ]
    },
    {
      "text": "Leistungen",
      "link": "/services"
    },
    {
      "text": "Über uns",
      "link": "/about"
    },
    {
      "text": "Referenzen",
      "link": "/references/",
      "items": [
        {
          "text": "Referenz 1",
          "link": "/references/test"
        }
      ]
    },
    {
      "text": "Aktuelles",
      "link": "/news"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "test": true
  },
  "headers": [],
  "relativePath": "test/api-examples.md",
  "filePath": "test/api-examples.md"
}

Page Frontmatter

{
  "test": true
}

Site Data

{
  "lang": "de-DE",
  "dir": "ltr",
  "title": "Sustena",
  "description": "Sustenas Webpräsenz",
  "base": "/",
  "head": [],
  "router": {
    "prefetchLinks": true
  },
  "appearance": true,
  "themeConfig": {
    "nav": [
      {
        "text": "Test",
        "link": "/test/",
        "items": [
          {
            "text": "API",
            "link": "/test/api-examples"
          },
          {
            "text": "Markdown",
            "link": "/test/markdown-examples"
          }
        ]
      },
      {
        "text": "Leistungen",
        "link": "/services"
      },
      {
        "text": "Über uns",
        "link": "/about"
      },
      {
        "text": "Referenzen",
        "link": "/references/",
        "items": [
          {
            "text": "Referenz 1",
            "link": "/references/test"
          }
        ]
      },
      {
        "text": "Aktuelles",
        "link": "/news"
      }
    ]
  },
  "locales": {},
  "scrollOffset": 134,
  "cleanUrls": false,
  "localeIndex": "root"
}

More

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