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

{
  "nav": [
    {
      "text": "Docs",
      "link": "/"
    },
    {
      "text": "Resume",
      "link": "/resume"
    }
  ],
  "sidebar": [
    {
      "text": "Javascript",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/javascript/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/javascript/api-examples"
        }
      ]
    },
    {
      "text": "CSS",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/css/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/css/api-examples"
        }
      ]
    },
    {
      "text": "HTML",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/html/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/html/api-examples"
        }
      ]
    },
    {
      "text": "Others",
      "items": [
        {
          "text": "Github-pages搭建指南",
          "link": "/others/github-pages-guide"
        }
      ]
    },
    {
      "items": [
        {
          "text": "Resume",
          "link": "/resume"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/Somnusochi"
    }
  ],
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "outline": {
    "label": "本页目录"
  },
  "footer": {
    "message": "With simple hearts, do what you love.",
    "copyright": "Copyright © 2016-2024 <a href=\"https://github.com/Somnusochi\">Somnusochi</a>"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

With simple hearts, do what you love.