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": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": {
    "/": [
      {
        "text": "api-examples",
        "link": "/api-examples"
      },
      {
        "text": "markdown-examples",
        "link": "/markdown-examples"
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/TomChicken-on-github/Tom_Chicken_Blog"
    },
    {
      "icon": "telegram",
      "link": "https://t.me/Tom_Chicken"
    }
  ],
  "permalinks": {
    "map": {},
    "inv": {}
  },
  "docAnalysisInfo": {
    "fileList": [
      {
        "filePath": "/opt/buildhome/repo/docs/api-examples.md",
        "relativePath": "api-examples.md"
      },
      {
        "filePath": "/opt/buildhome/repo/docs/markdown-examples.md",
        "relativePath": "markdown-examples.md"
      }
    ],
    "totalFileWords": 252,
    "eachFileWords": [
      {
        "fileInfo": {
          "filePath": "/opt/buildhome/repo/docs/api-examples.md",
          "relativePath": "api-examples.md"
        },
        "wordCount": 119,
        "readingTime": "1m",
        "frontmatter": {
          "outline": "deep"
        }
      },
      {
        "fileInfo": {
          "filePath": "/opt/buildhome/repo/docs/markdown-examples.md",
          "relativePath": "markdown-examples.md"
        },
        "wordCount": 133,
        "readingTime": "1m",
        "frontmatter": {}
      }
    ],
    "lastCommitTime": "2026-01-01 23:29:10"
  },
  "catalogues": {
    "arr": [],
    "map": {},
    "inv": {}
  },
  "posts": {
    "allPosts": [
      {
        "url": "/api-examples.html",
        "relativePath": "/api-examples.html",
        "frontmatter": {
          "outline": "deep"
        },
        "title": "Runtime API Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "Runtime API Examples\nThis page demonstrates usage of some of the runtime APIs provided by VitePress.\nThe 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:\n```md\n&lt;script setup\nimport { useData } from 'vitepress'\ncon"
      },
      {
        "url": "/",
        "relativePath": "/",
        "frontmatter": {
          "layout": "home",
          "hero": {
            "name": "Tom_Chickenのblog",
            "text": "Tom_Chicken personel blog",
            "tagline": "My great project tagline",
            "actions": [
              {
                "theme": "brand",
                "text": "Markdown Examples",
                "link": "/markdown-examples"
              },
              {
                "theme": "alt",
                "text": "API Examples",
                "link": "/api-examples"
              }
            ]
          },
          "features": [
            {
              "title": "Feature A",
              "details": "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            },
            {
              "title": "Feature B",
              "details": "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            },
            {
              "title": "Feature C",
              "details": "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            }
          ]
        },
        "title": "",
        "date": "1970-01-01 00:00:00",
        "capture": ""
      },
      {
        "url": "/markdown-examples.html",
        "relativePath": "/markdown-examples.html",
        "frontmatter": {},
        "title": "Markdown Extension Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "This page demonstrates some of the built-in markdown extensions provided by VitePress.\n Syntax Highlighting\nVitePress provides Syntax Highlighting powered by Shiki, with additional features like line-highlighting:\nInput\n````md\n```js{4}\nexport default {\n  data () {\n    return {\n      msg: 'Highlighte"
      }
    ],
    "originPosts": [
      {
        "url": "/api-examples.html",
        "relativePath": "/api-examples.html",
        "frontmatter": {
          "outline": "deep"
        },
        "title": "Runtime API Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "Runtime API Examples\nThis page demonstrates usage of some of the runtime APIs provided by VitePress.\nThe 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:\n```md\n&lt;script setup\nimport { useData } from 'vitepress'\ncon"
      },
      {
        "url": "/markdown-examples.html",
        "relativePath": "/markdown-examples.html",
        "frontmatter": {},
        "title": "Markdown Extension Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "This page demonstrates some of the built-in markdown extensions provided by VitePress.\n Syntax Highlighting\nVitePress provides Syntax Highlighting powered by Shiki, with additional features like line-highlighting:\nInput\n````md\n```js{4}\nexport default {\n  data () {\n    return {\n      msg: 'Highlighte"
      }
    ],
    "sortPostsByDateAndSticky": [
      {
        "url": "/api-examples.html",
        "relativePath": "/api-examples.html",
        "frontmatter": {
          "outline": "deep"
        },
        "title": "Runtime API Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "Runtime API Examples\nThis page demonstrates usage of some of the runtime APIs provided by VitePress.\nThe 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:\n```md\n&lt;script setup\nimport { useData } from 'vitepress'\ncon"
      },
      {
        "url": "/markdown-examples.html",
        "relativePath": "/markdown-examples.html",
        "frontmatter": {},
        "title": "Markdown Extension Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "This page demonstrates some of the built-in markdown extensions provided by VitePress.\n Syntax Highlighting\nVitePress provides Syntax Highlighting powered by Shiki, with additional features like line-highlighting:\nInput\n````md\n```js{4}\nexport default {\n  data () {\n    return {\n      msg: 'Highlighte"
      }
    ],
    "sortPostsByDate": [
      {
        "url": "/api-examples.html",
        "relativePath": "/api-examples.html",
        "frontmatter": {
          "outline": "deep"
        },
        "title": "Runtime API Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "Runtime API Examples\nThis page demonstrates usage of some of the runtime APIs provided by VitePress.\nThe 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:\n```md\n&lt;script setup\nimport { useData } from 'vitepress'\ncon"
      },
      {
        "url": "/markdown-examples.html",
        "relativePath": "/markdown-examples.html",
        "frontmatter": {},
        "title": "Markdown Extension Examples",
        "date": "1970-01-01 00:00:00",
        "capture": "This page demonstrates some of the built-in markdown extensions provided by VitePress.\n Syntax Highlighting\nVitePress provides Syntax Highlighting powered by Shiki, with additional features like line-highlighting:\nInput\n````md\n```js{4}\nexport default {\n  data () {\n    return {\n      msg: 'Highlighte"
      }
    ],
    "groupPostsByYear": {
      "1970 ": [
        {
          "url": "/api-examples.html",
          "relativePath": "/api-examples.html",
          "frontmatter": {
            "outline": "deep"
          },
          "title": "Runtime API Examples",
          "date": "1970-01-01 00:00:00",
          "capture": "Runtime API Examples\nThis page demonstrates usage of some of the runtime APIs provided by VitePress.\nThe 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:\n```md\n&lt;script setup\nimport { useData } from 'vitepress'\ncon"
        },
        {
          "url": "/markdown-examples.html",
          "relativePath": "/markdown-examples.html",
          "frontmatter": {},
          "title": "Markdown Extension Examples",
          "date": "1970-01-01 00:00:00",
          "capture": "This page demonstrates some of the built-in markdown extensions provided by VitePress.\n Syntax Highlighting\nVitePress provides Syntax Highlighting powered by Shiki, with additional features like line-highlighting:\nInput\n````md\n```js{4}\nexport default {\n  data () {\n    return {\n      msg: 'Highlighte"
        }
      ]
    },
    "groupPostsByYearMonth": {
      "1970 ": {
        "01": [
          {
            "url": "/api-examples.html",
            "relativePath": "/api-examples.html",
            "frontmatter": {
              "outline": "deep"
            },
            "title": "Runtime API Examples",
            "date": "1970-01-01 00:00:00",
            "capture": "Runtime API Examples\nThis page demonstrates usage of some of the runtime APIs provided by VitePress.\nThe 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:\n```md\n&lt;script setup\nimport { useData } from 'vitepress'\ncon"
          },
          {
            "url": "/markdown-examples.html",
            "relativePath": "/markdown-examples.html",
            "frontmatter": {},
            "title": "Markdown Extension Examples",
            "date": "1970-01-01 00:00:00",
            "capture": "This page demonstrates some of the built-in markdown extensions provided by VitePress.\n Syntax Highlighting\nVitePress provides Syntax Highlighting powered by Shiki, with additional features like line-highlighting:\nInput\n````md\n```js{4}\nexport default {\n  data () {\n    return {\n      msg: 'Highlighte"
          }
        ]
      }
    },
    "groupPosts": {
      "categories": {},
      "tags": {}
    },
    "groupCards": {
      "categories": [],
      "tags": []
    }
  }
}

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.

最近更新