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

{
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "原神剧情",
      "link": "/genshin/"
    },
    {
      "text": "LICENSE",
      "link": "/license-code"
    }
  ],
  "sidebar": {
    "/": [
      {
        "text": "原神剧情",
        "link": "/genshin/",
        "items": [
          {
            "text": "原神主线",
            "link": "/genshin/mainline/",
            "items": [
              {
                "text": "第三章",
                "link": "/genshin/mainline/chapter-3/"
              },
              {
                "text": "第四章",
                "link": "/genshin/mainline/chapter-4/"
              }
            ]
          },
          {
            "text": "原神活动",
            "link": "/genshin/event/"
          },
          {
            "text": "传说任务",
            "link": "/genshin/story/",
            "items": [
              {
                "text": "智慧主之章-纳西妲传说任务",
                "link": "/genshin/story/nahida/"
              },
              {
                "text": "潮涌之章-那维莱特传说任务",
                "link": "/genshin/story/neuvillette/"
              },
              {
                "text": "司颂之章-芙宁娜传说任务",
                "link": "/genshin/story/furina/"
              }
            ]
          }
        ]
      }
    ],
    "/genshin/mainline/chapter-3/": [
      {
        "text": "原神剧情",
        "link": "/genshin/"
      },
      {
        "text": "原神主线",
        "link": "/genshin/mainline/"
      },
      {
        "text": "传说任务",
        "link": "/genshin/story/"
      },
      {
        "text": "第三章",
        "link": "/genshin/mainline/chapter-3/",
        "items": [
          {
            "text": "第六幕-卡利贝尔",
            "link": "/genshin/mainline/chapter-3/act-6"
          }
        ]
      }
    ],
    "/genshin/mainline/chapter-4/": [
      {
        "text": "原神剧情",
        "link": "/genshin/"
      },
      {
        "text": "原神主线",
        "link": "/genshin/mainline/"
      },
      {
        "text": "传说任务",
        "link": "/genshin/story/"
      },
      {
        "text": "第四章",
        "link": "/genshin/mainline/chapter-4/",
        "items": [
          {
            "text": "第一幕-白露与黑潮的序诗",
            "link": "/genshin/mainline/chapter-4/act-1"
          },
          {
            "text": "第二幕-仿若无因飘落的轻雨",
            "link": "/genshin/mainline/chapter-4/act-2"
          },
          {
            "text": "第三幕-向深水中的晨星",
            "link": "/genshin/mainline/chapter-4/act-3"
          },
          {
            "text": "第四幕-谕示胎动的终焉之刻",
            "link": "/genshin/mainline/chapter-4/act-4"
          },
          {
            "text": "第五幕-罪人舞步旋",
            "link": "/genshin/mainline/chapter-4/act-5"
          }
        ]
      }
    ],
    "/genshin/story/nahida/": [
      {
        "text": "原神剧情",
        "link": "/genshin/"
      },
      {
        "text": "原神主线",
        "link": "/genshin/mainline/"
      },
      {
        "text": "传说任务",
        "link": "/genshin/story/"
      },
      {
        "text": "智慧主之章-纳西妲传说任务",
        "link": "/genshin/story/nahida/",
        "items": [
          {
            "text": "第一幕-余温",
            "link": "/genshin/story/nahida/act-1"
          },
          {
            "text": "第二幕-归乡",
            "link": "/genshin/story/nahida/act-2"
          }
        ]
      }
    ],
    "/genshin/story/neuvillette/": [
      {
        "text": "原神剧情",
        "link": "/genshin/"
      },
      {
        "text": "原神主线",
        "link": "/genshin/mainline/"
      },
      {
        "text": "传说任务",
        "link": "/genshin/story/"
      },
      {
        "text": "潮涌之章-那维莱特传说任务",
        "link": "/genshin/story/neuvillette/",
        "items": [
          {
            "text": "第一幕-往日留痕",
            "link": "/genshin/story/neuvillette/act-1"
          }
        ]
      }
    ],
    "/genshin/story/furina/": [
      {
        "text": "原神剧情",
        "link": "/genshin/"
      },
      {
        "text": "原神主线",
        "link": "/genshin/mainline/"
      },
      {
        "text": "传说任务",
        "link": "/genshin/story/"
      },
      {
        "text": "司颂之章-芙宁娜传说任务",
        "link": "/genshin/story/furina/",
        "items": [
          {
            "text": "第一幕-「水的女儿」",
            "link": "/genshin/story/furina/act-1"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/expliyh/irminsul-vite.git"
    },
    {
      "icon": {
        "svg": "<svg t=\"1703422580623\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"1602\" width=\"200\" height=\"200\"><path d=\"M729.32864 373.94944c-9.79456-5.94432-19.06176-6.784-19.14368-6.784l-1.06496-0.0512c-57.20064-3.8656-121.1648-5.83168-190.12608-5.83168l-13.98784 0.00512c-68.95616 0-132.92544 1.96096-190.12096 5.83168l-1.06496 0.0512c-0.08192 0-9.34912 0.83968-19.14368 6.784-15.04768 9.12896-24.27392 25.94816-27.4176 49.9712-10.07104 76.91264-4.38272 173.64992 0.18944 251.392 2.93888 49.96608 33.408 62.45888 85.04832 67.1488 10.78272 0.98816 69.08928 5.86752 159.50848 5.89312v-0.00512c90.4192-0.02048 148.72576-4.90496 159.5136-5.888 51.64032-4.68992 82.10944-17.18272 85.0432-67.1488 4.57728-77.74208 10.26048-174.47936 0.18944-251.392-3.1488-24.02816-12.37504-40.84736-27.42272-49.97632z m-390.9888 172.71808a23.64928 23.64928 0 0 1-31.68768-10.84416 23.68 23.68 0 0 1 10.84416-31.68768c2.03776-1.00352 50.69312-24.72448 110.5408-43.06432a23.68 23.68 0 1 1 13.88032 45.29152c-56.2944 17.24928-103.11168 40.07424-103.5776 40.30464z m268.89728 35.88608c-0.44032 2.23232-11.26912 54.64064-50.93888 54.64064-21.44256 0-36.10112-14.04928-44.98432-26.77248-8.69376 12.70784-22.80448 26.77248-42.65472 26.77248-35.5328 0-50.13504-48.26624-51.68128-53.77024a11.3664 11.3664 0 0 1 21.87776-6.1696c2.74944 9.6512 14.1312 37.20192 29.7984 37.20192 16.37376 0 28.89216-23.64416 31.98464-31.92832a11.37152 11.37152 0 0 1 10.6496-7.38816h0.06144c4.76672 0.03072 9.0112 3.02592 10.62912 7.50592 0.10752 0.28672 11.96544 31.81568 34.31424 31.81568 20.864 0 28.56448-35.95264 28.64128-36.32128a11.34592 11.34592 0 0 1 13.35808-8.93952 11.36128 11.36128 0 0 1 8.94464 13.35296z m110.11584-46.73536a23.68 23.68 0 0 1-31.68256 10.84416c-0.47104-0.2304-47.47264-23.1168-103.57248-40.30976a23.69024 23.69024 0 0 1-15.70816-29.58336 23.66976 23.66976 0 0 1 29.57824-15.70304c59.84768 18.33984 108.49792 42.0608 110.55104 43.06432a23.68 23.68 0 0 1 10.83392 31.68768z\" fill=\"#F16C8D\" p-id=\"1603\"></path><path d=\"M849.92 51.2H174.08c-67.8656 0-122.88 55.0144-122.88 122.88v675.84c0 67.87072 55.0144 122.88 122.88 122.88h675.84c67.87072 0 122.88-55.00928 122.88-122.88V174.08c0-67.86048-55.00928-122.88-122.88-122.88z m-36.60288 627.45088c-2.62656 44.57984-21.82144 78.63296-55.51616 98.48832-25.68192 15.13472-54.17472 19.48672-81.13664 21.9392-32.45568 2.94912-92.71808 6.09792-164.66432 6.1184-71.94112-0.02048-132.20864-3.16416-164.66432-6.1184-26.96192-2.45248-55.45472-6.80448-81.13152-21.9392-33.69472-19.85536-52.8896-53.90336-55.51104-98.4832-4.70528-80.13312-10.5728-179.85536 0.19456-262.10816C221.5424 335.16544 280.99072 311.57248 311.5008 310.37952a2482.64192 2482.64192 0 0 1 81.42336-4.08576c-7.53664-8.53504-19.88096-23.3216-28.81536-38.11328-13.73696-22.73792 8.52992-41.68704 8.52992-41.68704s23.68-20.36736 44.52864 5.21216c15.69792 19.26656 38.37952 55.99744 48.61952 72.95488l53.20704-0.21504c13.2608 0 26.33216 0.07168 39.2192 0.21504 10.24-16.95744 32.9216-53.6832 48.61952-72.95488 20.84352-25.57952 44.52864-5.21216 44.52864-5.21216s22.26176 18.94912 8.5248 41.68704c-8.9344 14.79168-21.27872 29.57824-28.81536 38.11328 28.35968 0.97792 55.56224 2.33984 81.42336 4.08064 30.5152 1.19808 89.9584 24.79104 100.61312 106.17344 10.7776 82.24768 4.9152 181.96992 0.20992 262.10304z\" fill=\"#F16C8D\" p-id=\"1604\"></path></svg>"
      },
      "link": "https://space.bilibili.com/95137550"
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "locales": {
        "root": {
          "translations": {
            "button": {
              "buttonText": "搜索",
              "buttonAriaLabel": "搜索"
            },
            "modal": {
              "noResultsText": "无法找到相关结果",
              "resetButtonTitle": "清除查询条件",
              "footer": {
                "selectText": "选择",
                "navigateText": "切换"
              }
            }
          }
        }
      }
    }
  }
}

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.