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

{
  "siteTitle": "竹巴噶举妙法宝箧",
  "logo": "/logo.png",
  "nav": [
    {
      "text": "主页",
      "link": "/"
    },
    {
      "text": "关于我们",
      "link": "/关于我们/"
    },
    {
      "text": "竹巴噶举",
      "link": "/竹巴噶举简介/"
    }
  ],
  "sidebar": [
    {
      "text": "内容导航",
      "items": [
        {
          "text": "竹巴噶举",
          "link": "/竹巴噶举简介/"
        }
      ]
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索",
          "buttonAriaLabel": "搜索"
        },
        "modal": {
          "displayDetails": "显示详细列表",
          "resetButtonTitle": "清除查询条件",
          "backButtonTitle": "关闭搜索",
          "noResultsText": "无法找到相关结果",
          "footer": {
            "selectText": "选择",
            "navigateText": "切换",
            "closeText": "关闭"
          }
        }
      }
    }
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep",
    "head": [
      [
        "meta",
        {
          "property": "og:title",
          "content": "Runtime API Examples | 竹巴噶举妙法宝箧"
        }
      ],
      [
        "meta",
        {
          "property": "og:description",
          "content": "竹巴噶举 · 藏汉译传法要"
        }
      ],
      [
        "meta",
        {
          "property": "og:image",
          "content": "https://DrukpaTrove.org/og-cover.png"
        }
      ],
      [
        "meta",
        {
          "property": "og:url",
          "content": "https://DrukpaTrove.org/api-examples.html"
        }
      ],
      [
        "meta",
        {
          "name": "twitter:title",
          "content": "Runtime API Examples | 竹巴噶举妙法宝箧"
        }
      ],
      [
        "meta",
        {
          "name": "twitter:description",
          "content": "竹巴噶举 · 藏汉译传法要"
        }
      ],
      [
        "meta",
        {
          "name": "twitter:image",
          "content": "https://DrukpaTrove.org/og-cover.png"
        }
      ]
    ]
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1783170310000
}

Page Frontmatter

{
  "outline": "deep",
  "head": [
    [
      "meta",
      {
        "property": "og:title",
        "content": "Runtime API Examples | 竹巴噶举妙法宝箧"
      }
    ],
    [
      "meta",
      {
        "property": "og:description",
        "content": "竹巴噶举 · 藏汉译传法要"
      }
    ],
    [
      "meta",
      {
        "property": "og:image",
        "content": "https://DrukpaTrove.org/og-cover.png"
      }
    ],
    [
      "meta",
      {
        "property": "og:url",
        "content": "https://DrukpaTrove.org/api-examples.html"
      }
    ],
    [
      "meta",
      {
        "name": "twitter:title",
        "content": "Runtime API Examples | 竹巴噶举妙法宝箧"
      }
    ],
    [
      "meta",
      {
        "name": "twitter:description",
        "content": "竹巴噶举 · 藏汉译传法要"
      }
    ],
    [
      "meta",
      {
        "name": "twitter:image",
        "content": "https://DrukpaTrove.org/og-cover.png"
      }
    ]
  ]
}

More

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

主页