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

{
  "search": {
    "provider": "local"
  },
  "nav": [
    {
      "text": "Blog",
      "link": "/posts/wsl2-proxy"
    },
    {
      "text": "CSS Tricks",
      "link": "/css/tab-circle-border"
    },
    {
      "text": "Aria2",
      "link": "https://aria2.65style.eu.org"
    },
    {
      "text": "OneDrive",
      "link": "https://oneindex.65style.eu.org"
    },
    {
      "text": "TV",
      "link": "https://tv.65style.eu.org"
    }
  ],
  "sidebar": [
    {
      "text": "Blog",
      "items": [
        {
          "text": "用 Cursor 打造生产级产品:全流程实战指南",
          "link": "/posts/corsor-guide"
        },
        {
          "text": "WSL2配置代理",
          "link": "/posts/wsl2-proxy"
        },
        {
          "text": "移动薅羊毛流量领取攻略",
          "link": "/posts/mobile-wan"
        }
      ]
    },
    {
      "text": "CSS Tricks",
      "items": [
        {
          "text": "Tab Circle Border",
          "link": "/css/tab-circle-border"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2023-present 65style"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.