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": "主页",
      "link": "/"
    }
  ],
  "sidebar": [
    {
      "text": "关于此文档",
      "items": [
        {
          "text": "基本信息",
          "link": "/about"
        },
        {
          "text": "友链",
          "link": "/share-links"
        },
        {
          "text": "FreeBSD",
          "link": "/freebsd/intro",
          "items": [
            {
              "text": "关于FreeBSD",
              "link": "/freebsd/about-fbsd"
            },
            {
              "text": "安装FreeBSD",
              "link": "/freebsd/install-fbsd"
            },
            {
              "text": "配置FreeBSD",
              "link": "/freebsd/conf-fbsd"
            }
          ]
        },
        {
          "text": "Yes Steve Model",
          "link": "/ysm/intro",
          "items": [
            {
              "text": "关于YSM",
              "link": "/ysm/about-ysm"
            },
            {
              "text": "兼容性",
              "link": "/ysm/compat"
            },
            {
              "text": "FreesiaII",
              "link": "/ysm/freesiaii"
            }
          ]
        },
        {
          "text": "暮光的衣橱",
          "link": "/wardrobe/intro",
          "items": [
            {
              "text": "关于衣橱",
              "link": "/wardrobe/about-wardrobe"
            },
            {
              "text": "旅途的开始",
              "link": "/wardrobe/getstarted"
            },
            {
              "text": "游戏侧配置",
              "link": "/wardrobe/game-conf"
            },
            {
              "text": "服务端侧配置",
              "link": "/wardrobe/server-conf"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/WiiRTwilight/documents-website"
    }
  ]
}

Page Data ​

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep",
    "head": [
      [
        "link",
        {
          "rel": "canonical",
          "href": "https://docs.timeless-twilight.com/api-examples"
        }
      ]
    ]
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md"
}

Page Frontmatter ​

{
  "outline": "deep",
  "head": [
    [
      "link",
      {
        "rel": "canonical",
        "href": "https://docs.timeless-twilight.com/api-examples"
      }
    ]
  ]
}

More ​

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