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 123123123

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

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

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

Results

Theme Data

{
  "nav": [
    {
      "text": "Index",
      "link": "/"
    },
    {
      "text": "Первые шаги",
      "link": "/первые-шаги/шаг-0"
    },
    {
      "text": "Api Examples",
      "link": "/api-examples"
    },
    {
      "text": "Примеры",
      "link": "/примеры/пример-запуск-модели"
    },
    {
      "text": "Test",
      "link": "/test"
    },
    {
      "text": "123",
      "link": "/123"
    }
  ],
  "sidebar": [
    {
      "text": "Index",
      "link": "/"
    },
    {
      "text": "Первые шаги",
      "collapsed": false,
      "items": [
        {
          "text": "Шаг 0",
          "link": "/первые-шаги/шаг-0"
        },
        {
          "text": "Markdown Examples",
          "link": "/первые-шаги/markdown-examples"
        }
      ]
    },
    {
      "text": "Api Examples",
      "link": "/api-examples"
    },
    {
      "text": "Примеры",
      "collapsed": false,
      "items": [
        {
          "text": "Пример запуск модели на python",
          "link": "/примеры/пример-запуск-модели"
        }
      ]
    },
    {
      "text": "Test",
      "link": "/test"
    },
    {
      "text": "123",
      "link": "/123"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "search": {
    "provider": "local"
  }
}

Page Data

{
  "title": "Api Examples",
  "description": "",
  "frontmatter": {
    "title": "Api Examples"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md"
}

Page Frontmatter

{
  "title": "Api Examples"
}

More

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