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

{
  "logo": "/logo.svg",
  "siteTitle": "Vela Open Doc",
  "sidebarMenuLabel": "菜单",
  "returnToTopLabel": "返回顶部",
  "outlineTitle": "本页目录",
  "darkModeSwitchLabel": "外观",
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    }
  ],
  "sidebar": [
    {
      "text": "文档",
      "items": [
        {
          "text": "设备参数",
          "link": "/docs/device"
        },
        {
          "text": "设备型号命名规律",
          "link": "/docs/name"
        },
        {
          "text": "米表系统合集",
          "link": "/docs/history"
        }
      ]
    },
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/zaona/vela-open-doc"
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "searchBoxPlaceholder": "搜索文档",
          "resetButtonTitle": "清除查询条件",
          "closeButtonAriaLabel": "关闭搜索",
          "noResultsText": "无法找到相关结果",
          "footer": {
            "selectText": "选择",
            "selectTextAriaLabel": "选择",
            "navigateText": "导航",
            "navigateTextAriaLabel": "导航到结果",
            "closeText": "关闭",
            "closeTextAriaLabel": "关闭搜索对话框"
          }
        }
      }
    }
  }
}

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.

贡献者

The avatar of contributor named as Zaona Zaona

页面历史