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": "入门",
      "link": "/生产文档/入门/开始"
    },
    {
      "text": "基础能力",
      "link": "/生产文档/基础能力/基本"
    }
  ],
  "sidebar": [
    {
      "text": "入门",
      "items": [
        {
          "text": "HF,启动!",
          "link": "/生产文档/入门/开始"
        },
        {
          "text": "创建系统",
          "link": "/生产文档/入门/创建系统"
        }
      ]
    },
    {
      "text": "基础能力",
      "items": [
        {
          "text": "BI",
          "link": "/生产文档/基础能力/基本"
        },
        {
          "text": "互相访问",
          "link": "/生产文档/基础能力/互相访问"
        },
        {
          "text": "监听",
          "link": "/生产文档/基础能力/监听"
        },
        {
          "text": "远程通信",
          "link": "/生产文档/基础能力/远程通信"
        },
        {
          "text": "远程通信进阶",
          "link": "/生产文档/基础能力/远程通信进阶"
        },
        {
          "text": "定时器",
          "link": "/生产文档/基础能力/定时器"
        },
        {
          "text": "数据储存",
          "link": "/生产文档/基础能力/数据储存"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

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.