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": "/"
    },
    {
      "text": "Wiki",
      "link": "/wiki/wiki-index"
    },
    {
      "text": "HyperOS JS应用库",
      "link": "/wiki/specials/HyperOS-JS-Apps"
    },
    {
      "text": "反馈",
      "link": "/feedback"
    },
    {
      "text": "关于",
      "link": "/about/about"
    }
  ],
  "sidebar": {
    "/wiki/": [
      {
        "text": "Wiki",
        "items": [
          {
            "text": "表格",
            "collapsed": true,
            "items": [
              {
                "text": "小米可穿戴设备代号对照表",
                "link": "/wiki/sheets/xiaomi-wearable-codes"
              }
            ]
          },
          {
            "text": "设备",
            "items": [
              {
                "text": "Xiaomi",
                "collapsed": true,
                "items": [
                  {
                    "text": "手环",
                    "collapsed": true,
                    "items": [
                      {
                        "text": "Xiaomi手环9Pro",
                        "link": "/wiki/product_wiki/Xiaomi/Smartband/9Pro"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/wiki/specials/HyperOS-JS-Apps/": [
      {
        "text": "HyperOS JS应用库",
        "items": [
          {
            "text": "概览",
            "link": "/wiki/specials/HyperOS-JS-Apps/"
          },
          {
            "text": "分类"
          }
        ]
      }
    ],
    "/about/": [
      {
        "text": "关于",
        "items": [
          {
            "text": "贡献者",
            "link": "/about/team"
          },
          {
            "text": "关于本站",
            "link": "/about/about"
          }
        ]
      }
    ]
  },
  "footer": {
    "message": "Released under <a href=\"https://ghfast.top/https://raw.githubusercontent.com/PieTech-WS/OpenWearWiki/master/LICENSE\">PowerAtom知识共享并开源许可VERSION2</a>",
    "copyright": "copyright 2025 PowerAtom Creative Commons Project及全体Wiki作者"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/PieTech-WS/OpenWearWiki-2NEXT"
    }
  ],
  "editLink": {
    "pattern": "https://github.com/PieTech-WS/OpenWearWiki-2NEXT/edit/tNEXT/src/:path"
  },
  "logo": "/logo.svg",
  "search": {
    "provider": "local"
  }
}

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.