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": "模块化",
      "items": [
        {
          "text": "架构概览",
          "link": "/zh/products/modularoverview"
        },
        {
          "text": "立方体 Cubic",
          "items": [
            {
              "text": "'☐' 框架",
              "link": "/zh/products/cubic/frames"
            },
            {
              "text": "接口面板",
              "link": "/zh/products/cubic/panels"
            },
            {
              "text": "功能模块",
              "link": "/zh/products/cubic/modules"
            }
          ]
        },
        {
          "text": "钟罩 BellJar",
          "items": [
            {
              "text": "'∩' 顶盖",
              "link": "/zh/products/belljar/caps"
            },
            {
              "text": "'○' 环段",
              "link": "/zh/products/belljar/collars"
            },
            {
              "text": "'_' 底板",
              "link": "/zh/products/belljar/plates"
            }
          ]
        }
      ]
    },
    {
      "text": "真空核心",
      "items": [
        {
          "text": "抽气站",
          "link": "/zh/products/vacuum-core/vacuum-pumps"
        },
        {
          "text": "低温捕集",
          "link": "/zh/products/vacuum-core/cryo-traps"
        }
      ]
    },
    {
      "text": "仪器",
      "items": [
        {
          "text": "小型离子溅射仪",
          "link": "/zh/products/instruments/mini-ion-sputter-coater"
        },
        {
          "text": "气泡检漏仪",
          "link": "/zh/products/instruments/bubble-leak-detector"
        }
      ]
    },
    {
      "text": "博客",
      "link": "/zh/posts/index"
    }
  ],
  "sidebar": {
    "/zh/products/": [
      {
        "text": "模块化",
        "items": [
          {
            "text": "架构概览",
            "link": "/zh/products/modularoverview"
          },
          {
            "text": "立方体 Cubic",
            "items": [
              {
                "text": "'☐' 框架",
                "link": "/zh/products/cubic/frames"
              },
              {
                "text": "接口面板",
                "link": "/zh/products/cubic/panels"
              },
              {
                "text": "功能模块",
                "link": "/zh/products/cubic/modules"
              }
            ]
          },
          {
            "text": "钟罩 BellJar",
            "items": [
              {
                "text": "'∩' 顶盖",
                "link": "/zh/products/belljar/caps"
              },
              {
                "text": "'○' 环段",
                "link": "/zh/products/belljar/collars"
              },
              {
                "text": "'_' 底板",
                "link": "/zh/products/belljar/plates"
              }
            ]
          }
        ]
      },
      {
        "text": "真空核心",
        "items": [
          {
            "text": "抽气站",
            "link": "/zh/products/vacuum-core/vacuum-pumps"
          },
          {
            "text": "低温捕集",
            "link": "/zh/products/vacuum-core/cryo-traps"
          }
        ]
      },
      {
        "text": "仪器",
        "items": [
          {
            "text": "小型离子溅射仪",
            "link": "/zh/products/instruments/mini-ion-sputter-coater"
          },
          {
            "text": "气泡检漏仪",
            "link": "/zh/products/instruments/bubble-leak-detector"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "twitter",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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