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:

PDF手册预览

提示:点击PDF内的下载按钮可保存手册,部分浏览器支持打印、缩放等原生功能。

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": "https://www.minnatec.com",
      "target": "_self"
    },
    {
      "text": "文档首页",
      "link": "/"
    },
    {
      "text": "API文档",
      "items": [
        {
          "text": "Markdown示例",
          "link": "/docs/markdown-examples"
        },
        {
          "text": "API示例",
          "link": "/docs/api-examples"
        },
        {
          "text": "MQTT协议",
          "link": "/docs/MQTT"
        },
        {
          "text": "PDF预览",
          "link": "/docs/pdf"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "核心文档",
      "collapsed": false,
      "items": [
        {
          "text": "markdown-examples",
          "link": "/docs/markdown-examples"
        },
        {
          "text": "api-examples",
          "link": "/docs/api-examples"
        },
        {
          "text": "MQTT",
          "link": "/docs/MQTT"
        },
        {
          "text": "PDF预览",
          "link": "/docs/pdf"
        }
      ]
    }
  ],
  "outline": {
    "level": [
      1,
      2
    ],
    "label": "本文目录"
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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