跳转到内容

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": "/大数据"
    },
    {
      "text": "成长思考",
      "link": "/成长思考"
    },
    {
      "text": "随手记",
      "link": "/随手记"
    },
    {
      "text": "面试宝典",
      "link": "/面试"
    },
    {
      "text": "开源工具",
      "link": "/工具"
    },
    {
      "text": "关于本站",
      "link": "/关于/",
      "items": [
        {
          "text": "网站用法",
          "items": [
            {
              "text": "markdown-examples",
              "link": "/about/examples/markdown-examples"
            },
            {
              "text": "api-examples",
              "link": "/about/examples/api-examples"
            }
          ]
        }
      ]
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "placeholder": "搜索文档",
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "searchBox": {
            "clearButtonTitle": "清除查询条件",
            "clearButtonAriaLabel": "清除查询条件",
            "closeButtonText": "关闭",
            "closeButtonAriaLabel": "关闭",
            "placeholderText": "搜索文档",
            "placeholderTextAskAi": "向 AI 提问:",
            "placeholderTextAskAiStreaming": "回答中...",
            "searchInputLabel": "搜索",
            "backToKeywordSearchButtonText": "返回关键字搜索",
            "backToKeywordSearchButtonAriaLabel": "返回关键字搜索"
          },
          "startScreen": {
            "recentSearchesTitle": "搜索历史",
            "noRecentSearchesText": "没有搜索历史",
            "saveRecentSearchButtonTitle": "保存至搜索历史",
            "removeRecentSearchButtonTitle": "从搜索历史中移除",
            "favoriteSearchesTitle": "收藏",
            "removeFavoriteSearchButtonTitle": "从收藏中移除",
            "recentConversationsTitle": "最近的对话",
            "removeRecentConversationButtonTitle": "从历史记录中删除对话"
          },
          "errorScreen": {
            "titleText": "无法获取结果",
            "helpText": "你可能需要检查你的网络连接"
          },
          "noResultsScreen": {
            "noResultsText": "无法找到相关结果",
            "suggestedQueryText": "你可以尝试查询",
            "reportMissingResultsText": "你认为该查询应该有结果?",
            "reportMissingResultsLinkText": "点击反馈"
          },
          "resultsScreen": {
            "askAiPlaceholder": "向 AI 提问: "
          },
          "askAiScreen": {
            "disclaimerText": "答案由 AI 生成,可能不准确,请自行验证。",
            "relatedSourcesText": "相关来源",
            "thinkingText": "思考中...",
            "copyButtonText": "复制",
            "copyButtonCopiedText": "已复制!",
            "copyButtonTitle": "复制",
            "likeButtonTitle": "赞",
            "dislikeButtonTitle": "踩",
            "thanksForFeedbackText": "感谢你的反馈!",
            "preToolCallText": "搜索中...",
            "duringToolCallText": "搜索 ",
            "afterToolCallText": "已搜索",
            "aggregatedToolCallText": "已搜索"
          },
          "footer": {
            "selectText": "选择",
            "submitQuestionText": "提交问题",
            "selectKeyAriaLabel": "Enter 键",
            "navigateText": "切换",
            "navigateUpKeyAriaLabel": "向上箭头",
            "navigateDownKeyAriaLabel": "向下箭头",
            "closeText": "关闭",
            "backToSearchText": "返回搜索",
            "closeKeyAriaLabel": "Esc 键",
            "poweredByText": "搜索提供者"
          }
        }
      },
      "miniSearch": {
        "options": {}
      }
    }
  },
  "sidebar": {
    "计算机基础": {
      "base": "/计算机基础",
      "items": [
        {
          "link": "/"
        },
        {
          "text": "数据结构",
          "collapsed": false,
          "items": [
            {
              "link": "/数据结构/"
            },
            {
              "text": "图",
              "collapsed": false,
              "items": [
                {
                  "text": "图结构",
                  "link": "/数据结构/图/图结构"
                }
              ]
            }
          ]
        },
        {
          "text": "架构",
          "collapsed": false,
          "items": [
            {
              "link": "/架构/"
            }
          ]
        },
        {
          "text": "算法",
          "collapsed": false,
          "items": [
            {
              "link": "/算法/"
            }
          ]
        },
        {
          "text": "设计模式",
          "collapsed": false,
          "items": [
            {
              "link": "/设计模式/"
            }
          ]
        }
      ]
    },
    "大数据": {
      "base": "/大数据",
      "items": [
        {
          "link": "/"
        }
      ]
    },
    "成长思考": {
      "base": "/成长思考",
      "items": [
        {
          "link": "/"
        },
        {
          "text": "不写,就无法思考",
          "link": "/不写,就无法思考"
        },
        {
          "text": "如何超过大多数人",
          "link": "/如何超过大多数人"
        }
      ]
    },
    "随手记": {
      "base": "/随手记",
      "items": [
        {
          "link": "/"
        },
        {
          "text": "虚拟机如何使用主机侧代理软件",
          "link": "/虚拟机如何使用主机侧代理软件"
        },
        null
      ]
    },
    "面试": {
      "base": "/面试",
      "items": [
        {
          "link": "/"
        }
      ]
    },
    "工具": {
      "base": "/工具",
      "items": [
        {
          "text": "excel对比神器",
          "link": "/excel对比神器"
        },
        {
          "link": "/"
        },
        null
      ]
    },
    "关于": {
      "base": "/关于",
      "items": [
        {
          "link": "/"
        },
        {
          "text": "examples",
          "collapsed": false,
          "items": [
            {
              "text": "api-examples",
              "link": "/examples/api-examples"
            },
            {
              "text": "markdown-examples",
              "link": "/examples/markdown-examples"
            }
          ]
        }
      ]
    }
  },
  "outline": {
    "level": "deep",
    "label": "页面导航"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/shawndanger"
    }
  ],
  "editLink": {
    "pattern": "https://github.com/shawndanger/shawndanger.github.io/edit/master/docs/src/:path",
    "text": "在Github上编辑此页面"
  },
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2024-2025 shawndanger."
  },
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "lastUpdated": {
    "text": "最后更新于"
  },
  "notFound": {
    "title": "页面未找到",
    "quote": "但如果你不改变方向,并且继续寻找,你可能最终会到达你所前往的地方。",
    "linkLabel": "前往首页",
    "linkText": "带我回首页"
  },
  "langMenuLabel": "多语言",
  "returnToTopLabel": "回到顶部",
  "sidebarMenuLabel": "菜单",
  "darkModeSwitchLabel": "主题",
  "lightModeSwitchTitle": "切换到浅色模式",
  "darkModeSwitchTitle": "切换到深色模式",
  "skipToContentLabel": "跳转到内容",
  "aside": true
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.