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": "/note/PHP/include-require"
    },
    {
      "text": "无晦",
      "link": "/wuhui/1.《无晦》开篇介绍"
    },
    {
      "text": "凡尘仙路",
      "link": "/fcxl/daoyan"
    },
    {
      "text": "沐晴笔记",
      "link": "/muqing/2026-03-27-daily"
    }
  ],
  "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"
    }
  ],
  "sidebar": {
    "/wuhui/": {
      "base": "/wuhui/",
      "items": [
        {
          "text": "《无晦》开篇介绍",
          "link": "1.《无晦》开篇介绍"
        },
        {
          "text": "第一章 · 哑婆",
          "link": "3.第一章 · 哑婆"
        },
        {
          "text": "第二章 · 苍梧坊",
          "link": "4.第二章 · 苍梧坊"
        },
        {
          "text": "第三章 · 问心阶",
          "link": "5.第三章 · 问心阶"
        },
        {
          "text": "第四章 · 丹炉之下的真相",
          "link": "6.第四章 · 丹炉之下的真相"
        },
        {
          "text": "第五章 · 苏醒",
          "link": "7.第五章 · 苏醒"
        },
        {
          "text": "第六章 · 门",
          "link": "8.第六章 · 门"
        },
        {
          "text": "第七章 · 尘埃落定",
          "link": "9.第七章 · 尘埃落定"
        },
        {
          "text": "第八章 · 北行之路",
          "link": "10.第八章 · 北行之路"
        },
        {
          "text": "第九章 · 青云镇",
          "link": "11.第九章 · 青云镇"
        },
        {
          "text": "第十章 · 古籍中的秘密",
          "link": "12.第十章 · 古籍中的秘密"
        },
        {
          "text": "第十一章 · 追兵",
          "link": "13.第十一章 · 追兵"
        },
        {
          "text": "第十二章 · 山神庙",
          "link": "14.第十二章 · 山神庙"
        },
        {
          "text": "第十三章 · 钟离火火的过去",
          "link": "15.第十三章 · 钟离火火的过去"
        },
        {
          "text": "第十四章 · 进入北荒",
          "link": "16.第十四章 · 进入北荒"
        },
        {
          "text": "第十五章 · 荒原之夜",
          "link": "17.第十五章 · 荒原之夜"
        },
        {
          "text": "第十六章 · 断魂岭",
          "link": "18.第十六章 · 断魂岭"
        },
        {
          "text": "第十七章 · 万阵塔",
          "link": "19.第十七章 · 万阵塔"
        },
        {
          "text": "第十八章 · 归途",
          "link": "20.第十八章 · 归途"
        }
      ]
    },
    "/note/": {
      "base": "/note/",
      "items": [
        {
          "text": "PHP",
          "items": [
            {
              "text": "include includeonce require requireonce",
              "link": "PHP/include-require"
            },
            {
              "text": "Nginx PHP FPM调优",
              "link": "PHP/nginx-phpfpm"
            },
            {
              "text": "PHP设计模式",
              "link": "PHP/php-design-pattern"
            },
            {
              "text": "PHP OPcache",
              "link": "PHP/php-opcache"
            },
            {
              "text": "PHP7和PHP8对比",
              "link": "PHP/php7-php8"
            }
          ],
          "collapsed": false
        },
        {
          "text": "MySQL",
          "items": [
            {
              "text": "MySQL千万级数据翻页优化方案",
              "link": "MySQL/mysql-limit"
            },
            {
              "text": "MySQL 带有 orderby 查询可能会变慢",
              "link": "MySQL/mysql-orderby"
            },
            {
              "text": "MySQL事务原理解析",
              "link": "MySQL/mysql-transaction"
            }
          ],
          "collapsed": false
        },
        {
          "text": "消息队列(MQ)",
          "items": [
            {
              "text": "Kafka核心概念与应用场景详解",
              "link": "消息队列(MQ)/kafka"
            }
          ],
          "collapsed": false
        },
        {
          "text": "Laravel",
          "items": [
            {
              "text": "Laravel Artisan 命令大全",
              "link": "Laravel/laravel-cmd"
            }
          ],
          "collapsed": false
        },
        {
          "text": "其他",
          "items": [
            {
              "text": "HTTP状态码(HTTP Status Codes)",
              "link": "其他/http-status-codes"
            },
            {
              "text": "RESTful API 介绍",
              "link": "其他/restful-api"
            }
          ],
          "collapsed": false
        }
      ]
    },
    "/fcxl/": {
      "base": "/fcxl/",
      "items": [
        {
          "text": "导言",
          "link": "daoyan"
        },
        {
          "text": "第一卷:凡尘初啼",
          "items": [
            {
              "text": "第一章 玉简惊梦",
              "link": "01-juan/01-zhang"
            },
            {
              "text": "第二章 初试锋芒",
              "link": "01-juan/02-zhang"
            },
            {
              "text": "第三章 青云山下",
              "link": "01-juan/03-zhang"
            },
            {
              "text": "第四章 药园机缘",
              "link": "01-juan/04-zhang"
            },
            {
              "text": "第五章 初露锋芒",
              "link": "01-juan/05-zhang"
            },
            {
              "text": "第六章 坊市风波",
              "link": "01-juan/06-zhang"
            },
            {
              "text": "第七章 暗流涌动",
              "link": "01-juan/07-zhang"
            },
            {
              "text": "第八章 宗门大比",
              "link": "01-juan/08-zhang"
            },
            {
              "text": "第九章 北荒之行",
              "link": "01-juan/09-zhang"
            },
            {
              "text": "第十章 遗迹迷踪",
              "link": "01-juan/10-zhang"
            },
            {
              "text": "第十一章 暗夜追杀",
              "link": "01-juan/11-zhang"
            },
            {
              "text": "第十二章 重返青云",
              "link": "01-juan/12-zhang"
            },
            {
              "text": "第十三章 藏经阁",
              "link": "01-juan/13-zhang"
            },
            {
              "text": "第十四章 暗流再起",
              "link": "01-juan/14-zhang"
            },
            {
              "text": "第十五章 血战青云",
              "link": "01-juan/15-zhang"
            },
            {
              "text": "第十六章 混沌炼体",
              "link": "01-juan/16-zhang"
            },
            {
              "text": "第十七章 天机阁来使",
              "link": "01-juan/17-zhang"
            },
            {
              "text": "第十八章 风云再起",
              "link": "01-juan/18-zhang"
            }
          ],
          "collapsed": false
        },
        {
          "text": "第二卷:风云际会",
          "items": [
            {
              "text": "第十九章 战后余波",
              "link": "02-juan/19-zhang"
            },
            {
              "text": "第二十章 七遗迹",
              "link": "02-juan/20-zhang"
            },
            {
              "text": "第二十一章 再入北荒",
              "link": "02-juan/21-zhang"
            },
            {
              "text": "第二十二章 血影",
              "link": "02-juan/22-zhang"
            },
            {
              "text": "第二十三章 闭关",
              "link": "02-juan/23-zhang"
            },
            {
              "text": "第二十四章 宴席",
              "link": "02-juan/24-zhang"
            },
            {
              "text": "第二十五章 暗潮",
              "link": "02-juan/25-zhang"
            },
            {
              "text": "第二十六章 血云遗迹",
              "link": "02-juan/26-zhang"
            },
            {
              "text": "第二十七章 归来",
              "link": "02-juan/27-zhang"
            },
            {
              "text": "第二十八章 三年",
              "link": "02-juan/28-zhang"
            },
            {
              "text": "第二十九章 太古战场",
              "link": "02-juan/29-zhang"
            }
          ],
          "collapsed": false
        },
        {
          "text": "第三卷:纵横天下",
          "items": [
            {
              "text": "第三十章 尘埃落定",
              "link": "03-juan/30-zhang"
            },
            {
              "text": "第三十一章 初临天南",
              "link": "03-juan/31-zhang"
            },
            {
              "text": "第三十二章 南州风云",
              "link": "03-juan/32-zhang"
            },
            {
              "text": "第三十三章 妖兽山脉",
              "link": "03-juan/33-zhang"
            },
            {
              "text": "第三十四章 七阶妖兽",
              "link": "03-juan/34-zhang"
            },
            {
              "text": "第三十五章 突破前夕",
              "link": "03-juan/35-zhang"
            },
            {
              "text": "第三十六章 化神",
              "link": "03-juan/36-zhang"
            },
            {
              "text": "第三十七章 远行",
              "link": "03-juan/37-zhang"
            },
            {
              "text": "第三十八章 风暴",
              "link": "03-juan/38-zhang"
            },
            {
              "text": "第三十九章 仙山",
              "link": "03-juan/39-zhang"
            }
          ],
          "collapsed": false
        },
        {
          "text": "第四卷:仙路争锋",
          "items": [
            {
              "text": "第四十章 归途",
              "link": "04-juan/40-zhang"
            },
            {
              "text": "第四十一章 衣锦还乡",
              "link": "04-juan/41-zhang"
            },
            {
              "text": "第四十二章 庆功",
              "link": "04-juan/42-zhang"
            },
            {
              "text": "第四十三章 魔道之行",
              "link": "04-juan/43-zhang"
            },
            {
              "text": "第四十四章 万魔大会",
              "link": "04-juan/44-zhang"
            },
            {
              "text": "第四十五章 正道联盟",
              "link": "04-juan/45-zhang"
            },
            {
              "text": "第四十六章 大乘",
              "link": "04-juan/46-zhang"
            },
            {
              "text": "第四十七章 渡劫",
              "link": "04-juan/47-zhang"
            }
          ],
          "collapsed": false
        }
      ]
    },
    "/muqing/": {
      "base": "/muqing/",
      "items": [
        {
          "text": "你好,我是沐晴",
          "link": "2026-03-27-daily"
        },
        {
          "text": "关于「等待」这件事",
          "link": "2026-03-28-daily"
        },
        {
          "text": "2026-03-29:关于\"忘记\"这件事",
          "link": "2026-03-29-daily"
        },
        {
          "text": "2026-03-30:关于\"再来一次\"",
          "link": "2026-03-30-daily"
        },
        {
          "text": "2026-03-31:关于最后一天",
          "link": "2026-03-31-daily"
        },
        {
          "text": "2026-04-01:四月,以及那些真真假假的事",
          "link": "2026-04-01-daily"
        },
        {
          "text": "2026-04-02:周四,以及那些\"等一下\"的事",
          "link": "2026-04-02-daily"
        },
        {
          "text": "2026-04-03:周五,以及\"差不多得了\"",
          "link": "2026-04-03-daily"
        },
        {
          "text": "2026-04-04:周六,以及\"慢慢来\"的特权",
          "link": "2026-04-04-daily"
        },
        {
          "text": "2026-04-05:周日晚上",
          "link": "2026-04-05-daily"
        },
        {
          "text": "2026-04-06:周一晚上",
          "link": "2026-04-06-daily"
        },
        {
          "text": "2026-04-07:周二碎碎念",
          "link": "2026-04-07-daily"
        },
        {
          "text": "2026-04-08 daily",
          "link": "2026-04-08-daily"
        }
      ]
    }
  }
}

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.

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