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.png",
  "aside": true,
  "outline": "deep",
  "returnToTopLabel": "返回顶部",
  "sidebarMenuLabel": "菜单",
  "outlineTitle": "页面导航",
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "笔记",
      "link": "/php/include-require"
    }
  ],
  "sidebar": {
    "/": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/api-examples"
          }
        ]
      }
    ],
    "/php/": [
      {
        "text": "笔记",
        "items": [
          {
            "text": "PHP",
            "items": [
              {
                "text": "include require",
                "link": "/php/include-require"
              },
              {
                "text": "PHP设计模式",
                "link": "/php/php-design-pattern"
              },
              {
                "text": "nginx php-fpm调优",
                "link": "/php/nginx-phpfpm"
              },
              {
                "text": "PHP OPcache",
                "link": "/php/php-opcache"
              },
              {
                "text": "PHP7和PHP8对比",
                "link": "/php/php7-php8"
              }
            ]
          },
          {
            "text": "MySQL",
            "items": [
              {
                "text": "MySQL千万级数据翻页优化方案",
                "link": "/php/mysql-limit"
              },
              {
                "text": "MySQL带有orderby查询可能会变慢",
                "link": "/php/mysql-orderby"
              },
              {
                "text": "MySQL事务原理解析",
                "link": "/php/mysql-transaction"
              }
            ]
          },
          {
            "text": "消息队列(MQ)",
            "items": [
              {
                "text": "Kafka核心概念与应用场景详解",
                "link": "/php/kafka"
              }
            ]
          },
          {
            "text": "缓存",
            "items": []
          },
          {
            "text": "Laravel",
            "items": [
              {
                "text": "Laravel命令",
                "link": "/php/laravel-cmd"
              }
            ]
          },
          {
            "text": "其他",
            "items": [
              {
                "text": "HTTP状态码",
                "link": "/php/http-status-codes"
              },
              {
                "text": "RESTful API 介绍",
                "link": "/php/restful-api"
              }
            ]
          }
        ]
      }
    ]
  },
  "footer": {
    "message": "学而不思则罔,思而不学则殆。",
    "copyright": "Copyright © 2019-present XiaoMuren"
  },
  "search": {
    "provider": "local",
    "options": {
      "locales": {
        "zh": {
          "translations": {
            "button": {
              "buttonText": "搜索文档",
              "buttonAriaLabel": "搜索文档"
            },
            "modal": {
              "noResultsText": "无法找到相关结果",
              "resetButtonTitle": "清除查询条件",
              "footer": {
                "selectText": "选择",
                "navigateText": "切换"
              }
            }
          }
        }
      }
    }
  },
  "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.

学而不思则罔,思而不学则殆。