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": "imgs/doghead.jpg",
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/examples/markdown-examples"
    },
    {
      "text": "RTK",
      "items": [
        {
          "text": "RTKLIB手册",
          "link": "/algorithm/RTKLIB手册/"
        },
        {
          "text": "RTKLIB源码解析",
          "link": "/algorithm/RTKLIB源码解析/"
        }
      ]
    },
    {
      "text": "GUI",
      "items": [
        {
          "text": "Vitepress",
          "link": "/gui/vitepress/01-tutorials"
        }
      ]
    },
    {
      "text": "Knowledge",
      "link": "/knowledge/01-common"
    }
  ],
  "sidebar": {
    "/examples/": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/examples/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/examples/api-examples"
          }
        ]
      }
    ],
    "/algorithm/RTKLIB手册/": [
      {
        "text": "RTKLIB手册",
        "link": "/algorithm/RTKLIB手册/"
      },
      {
        "text": "1. 摘要",
        "link": "/algorithm/RTKLIB手册/01-overview"
      },
      {
        "text": "2. 准备",
        "link": "/algorithm/RTKLIB手册/02-prepare"
      },
      {
        "text": "3. 操作指南",
        "link": "/algorithm/RTKLIB手册/04-build"
      },
      {
        "text": "附录A. CUI指令",
        "link": "/algorithm/RTKLIB手册/05-appendixA"
      },
      {
        "text": "附录B. 文件格式",
        "link": "/algorithm/RTKLIB手册/06-appendixB"
      },
      {
        "text": "附录C. C API",
        "link": "/algorithm/RTKLIB手册/07-appendixC"
      },
      {
        "text": "附录D. 文件与报文",
        "link": "/algorithm/RTKLIB手册/08-appendixD"
      },
      {
        "text": "附录E. 模型与算法",
        "link": "/algorithm/RTKLIB手册/09-appendixE"
      },
      {
        "text": "附录F. 配置文件",
        "link": "/algorithm/RTKLIB手册/10-appendixF"
      },
      {
        "text": "附录G. GNSS信号",
        "link": "/algorithm/RTKLIB手册/11-appendixG"
      },
      {
        "text": "参考文献",
        "link": "/algorithm/RTKLIB手册/12-reference"
      }
    ],
    "/gui/vitepress/": [
      {
        "text": "Vitepress",
        "link": "/gui/vitepress/01-tutorials"
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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