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": "/icon/FA1.svg",
  "outline": [
    2,
    3
  ],
  "outlineTitle": "当前页面",
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "returnToTopLabel": "返回顶部",
  "sidebarMenuLabel": "菜单",
  "darkModeSwitchLabel": "外观",
  "lastUpdated": {
    "text": "最后更新于"
  },
  "localeLinks": {
    "items": [
      {
        "text": "简体中文",
        "link": "/"
      },
      {
        "text": "English",
        "link": "/en"
      }
    ]
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "开始阅读",
      "link": "/web/outline"
    },
    {
      "text": "资源",
      "items": [
        {
          "text": "vitepress文档",
          "link": "https://vitepress.dev/"
        },
        {
          "text": "部署文档",
          "link": "https://vuepress.vuejs.org/zh/guide/deploy.html#google-firebase"
        },
        {
          "text": "部署配置-1",
          "link": "https://juejin.cn/post/7164276166084263972"
        },
        {
          "text": "部署配置-2",
          "link": "https://juejin.cn/post/7064746265266880549#heading-18"
        },
        {
          "text": "解决执行bash",
          "link": "https://blog.csdn.net/air__Heaven/article/details/125756680"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "开始阅读",
      "link": "/web/outline"
    },
    {
      "text": "🍍基础",
      "items": [
        {
          "text": "🍓Web前端",
          "collapsed": true,
          "items": [
            {
              "text": "大纲",
              "link": "/web/outline"
            },
            {
              "text": "指引",
              "link": "/web/zhiyin"
            }
          ]
        },
        {
          "text": "🧀JavaScript",
          "collapsed": true,
          "items": [
            {
              "text": "基础",
              "link": "/javascript/Basics"
            },
            {
              "text": "进阶",
              "link": "/javascript/Upgrade"
            }
          ]
        },
        {
          "text": "🥞Vue.js",
          "collapsed": true,
          "items": [
            {
              "text": "基础",
              "link": "/Vue/Basics"
            },
            {
              "text": "进阶",
              "link": "/Vue/Upgrade"
            }
          ]
        },
        {
          "text": "🥣React.js",
          "collapsed": true,
          "items": [
            {
              "text": "基础",
              "link": "/React/Basics"
            },
            {
              "text": "进阶",
              "link": "/React/Upgrade"
            }
          ]
        },
        {
          "text": "🥝Node.js",
          "collapsed": true,
          "items": [
            {
              "text": "基础",
              "link": "/Node/Basics"
            },
            {
              "text": "进阶",
              "link": "/Node/Upgrade"
            }
          ]
        },
        {
          "text": "🥑Git",
          "collapsed": true,
          "items": [
            {
              "text": "基础",
              "link": "/Git/Basics"
            },
            {
              "text": "进阶",
              "link": "/Git/Upgrade"
            }
          ]
        },
        {
          "text": "🍎Examples",
          "collapsed": true,
          "items": [
            {
              "text": "Markdown Examples",
              "link": "/Examples/markdown-examples"
            },
            {
              "text": "Runtime API Examples",
              "link": "/Examples/api-examples"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/faluoys"
    },
    {
      "icon": {
        "svg": "<svg id=\"douyin\" t=\"1570181112474\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2916\" width=\"128\" height=\"128\"> <path d=\"M937.386667 423.850667a387.84 387.84 0 0 1-232.874667-77.824v352.341333C704.512 878.250667 565.930667 1024 394.922667 1024S85.333333 878.250667 85.333333 698.368c0-179.882667 138.581333-325.632 309.589334-325.632 17.066667 0 33.706667 1.450667 49.92 4.266667v186.624a131.754667 131.754667 0 0 0-48.64-9.216c-76.288 0-138.154667 65.024-138.154667 145.322666 0 80.213333 61.866667 145.322667 138.24 145.322667 76.202667 0 138.069333-65.109333 138.069333-145.322667V0h172.714667c0 134.485333 103.68 243.541333 231.594667 243.541333v180.309334h-1.28\" p-id=\"2917\"></path> </svg>"
      },
      "link": "https://v.douyin.com/iRGFsyeS/ 8@5.com 02/22"
    }
  ],
  "footer": {
    "message": "<a href=\"#\" target=\"_blank\">xxxxxxx</a>",
    "copyright": "Copyright © 2023-present xxxxxx"
  },
  "editLink": {
    "pattern": "https://github.com/faluoys/docsVitepress/edit/main/docs/:path",
    "text": "在 GitHub 上编辑此页面"
  },
  "search": {
    "provider": "local",
    "options": {
      "locales": {
        "zh": {
          "placeholder": "搜索文档",
          "translations": {
            "button": {
              "buttonText": "搜索文档",
              "buttonAriaLabel": "搜索文档"
            },
            "modal": {
              "searchBox": {
                "resetButtonTitle": "清除查询条件",
                "resetButtonAriaLabel": "清除查询条件",
                "cancelButtonText": "取消",
                "cancelButtonAriaLabel": "取消"
              },
              "startScreen": {
                "recentSearchesTitle": "搜索历史",
                "noRecentSearchesText": "没有搜索历史",
                "saveRecentSearchButtonTitle": "保存至搜索历史",
                "removeRecentSearchButtonTitle": "从搜索历史中移除",
                "favoriteSearchesTitle": "收藏",
                "removeFavoriteSearchButtonTitle": "从收藏中移除"
              },
              "errorScreen": {
                "titleText": "无法获取结果",
                "helpText": "你可能需要检查你的网络连接"
              },
              "footer": {
                "selectText": "选择",
                "navigateText": "切换",
                "closeText": "关闭",
                "searchByText": "搜索提供者"
              },
              "noResultsScreen": {
                "noResultsText": "无法找到相关结果",
                "suggestedQueryText": "你可以尝试查询",
                "reportMissingResultsText": "你认为该查询应该有结果?",
                "reportMissingResultsLinkText": "点击反馈"
              }
            }
          }
        }
      }
    }
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

xxxxxxx