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": false,
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "简介",
      "items": [
        {
          "text": "博客介绍",
          "link": "/introduction"
        }
      ]
    },
    {
      "text": "实用技巧",
      "items": [
        {
          "text": "Google搜索",
          "link": "/实用技巧/Google高级搜索"
        },
        {
          "text": "Vim常用命令",
          "link": "/vim-commands"
        }
      ]
    },
    {
      "text": "文章",
      "items": [
        {
          "text": "Gost代理",
          "link": "/软件/gost"
        },
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ],
  "footer": {
    "message": "",
    "copyright": "Copyright © 2018-present 李秸康 | <a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">湘ICP备2023031573号</a> |  <a href=\"https://beian.mps.gov.cn/#/query/webSearch?code=43060202000505\" target=\"_blank\"><img src=\"/备案图标.png\" style=\"vertical-align: middle; margin-right: 4px; height: 1em; display:inline\" alt=\"公安备案图标\">湘公网安备43060202000505</a>"
  }
}

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.