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": {
    "light": "/book.png",
    "dark": "/book-dark.png"
  },
  "search": {
    "provider": "local",
    "options": {
      "previewLength": 62,
      "buttonLabel": "搜索",
      "placeholder": "请输入关键词",
      "allow": [
        "/zh/",
        "/ja/"
      ],
      "ignore": [],
      "locales": {
        "zh": {
          "translations": {
            "button": {
              "buttonText": "搜索文档",
              "buttonAriaLabel": "搜索文档"
            },
            "modal": {
              "noResultsText": "无法找到相关结果",
              "resetButtonTitle": "清除查询条件",
              "footer": {
                "selectText": "选择",
                "navigateText": "切换"
              }
            }
          }
        }
      }
    }
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "示例",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        },
        {
          "text": "开发学习",
          "link": "/development"
        },
        {
          "text": "NodeJS文档",
          "link": "/node-learn"
        },
        {
          "text": "CI/CD",
          "link": "/src/build-story/jenkins"
        },
        {
          "text": "AI效率工具",
          "link": "/src/ai-tool"
        }
      ]
    },
    {
      "text": "日本語の勉強",
      "link": "/japanese"
    }
  ],
  "sidebar": [
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    },
    {
      "text": "开发学习",
      "items": [
        {
          "text": "开发学习",
          "link": "/development"
        }
      ]
    },
    {
      "text": "项目文档",
      "items": [
        {
          "text": "项目文档",
          "link": "/api-project"
        }
      ]
    },
    {
      "text": "NodeJS",
      "items": [
        {
          "text": "NodeJS",
          "link": "/node-learn"
        },
        {
          "text": "Express&Koa",
          "link": "/src/nodejs/express"
        },
        {
          "text": "Nest",
          "link": "/src/nodejs/nest"
        },
        {
          "text": "Mysql",
          "link": "/src/nodejs/mysql"
        },
        {
          "text": "Mongodb",
          "link": "/src/nodejs/mongodb"
        },
        {
          "text": "Redis",
          "link": "/src/nodejs/redis"
        },
        {
          "text": "面试题",
          "link": "/src/nodejs/interview"
        }
      ]
    },
    {
      "text": "golang",
      "items": [
        {
          "text": "go",
          "link": "/src/golang/index"
        },
        {
          "text": "gin",
          "link": "/src/golang/gin"
        },
        {
          "text": "goframe",
          "link": "/src/golang/goframe"
        },
        {
          "text": "grpc",
          "link": "/src/golang/grpc"
        }
      ]
    },
    {
      "text": "AI效率工具",
      "items": [
        {
          "text": "AI效率工具",
          "link": "/src/ai-tool/index"
        }
      ]
    },
    {
      "text": "CI/CD",
      "items": [
        {
          "text": "Jenkins",
          "link": "/src/build-story/jenkins"
        },
        {
          "text": "Docker",
          "link": "/src/build-story/docker"
        },
        {
          "text": "Git",
          "link": "/src/build-story/git"
        },
        {
          "text": "Gitlab",
          "link": "/src/build-story/gitlab"
        },
        {
          "text": "Github",
          "link": "/src/build-story/github"
        }
      ]
    },
    {
      "text": "Japanese",
      "items": [
        {
          "text": "日本語の勉強",
          "link": "/japanese"
        },
        {
          "text": "影子跟读",
          "link": "/janpan-shadow-reading"
        },
        {
          "text": "词汇",
          "link": "/janpan-words"
        },
        {
          "text": "文法",
          "link": "/janpan-grammar"
        },
        {
          "text": "听力",
          "link": "/janpan-listening"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

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.