· by John Doe

API Examples

Demonstrates usage of some of the runtime APIs provided by VitePress.


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

{
  "author": {
    "name": "Gabriel Cozma",
    "link": "https://gxbs.me/"
  },
  "nav": [
    {
      "text": "Use",
      "link": "/use"
    },
    {
      "text": "About",
      "link": "/about"
    },
    {
      "text": "Source Code",
      "link": "https://github.com/GabsEdits/tipps"
    }
  ]
}

Page Data

{
  "title": "API Examples",
  "description": "Demonstrates usage of some of the runtime APIs provided by VitePress.",
  "frontmatter": {
    "layout": "post",
    "title": "API Examples",
    "date": "2024-06-01T00:00:00.000Z",
    "description": "Demonstrates usage of some of the runtime APIs provided by VitePress.",
    "author": "John Doe",
    "tags": [
      "Vitepress",
      "API",
      "Examples"
    ]
  },
  "headers": [],
  "relativePath": "posts/api-examples.md",
  "filePath": "posts/api-examples.md"
}

Page Frontmatter

{
  "layout": "post",
  "title": "API Examples",
  "date": "2024-06-01T00:00:00.000Z",
  "description": "Demonstrates usage of some of the runtime APIs provided by VitePress.",
  "author": "John Doe",
  "tags": [
    "Vitepress",
    "API",
    "Examples"
  ]
}

More

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