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": "快速开始",
      "items": [
        {
          "text": "欢迎",
          "link": "/quickstart/welcome"
        },
        {
          "text": "概念",
          "link": "/quickstart/concepts"
        },
        {
          "text": "创建项目",
          "link": "/quickstart/create-project"
        },
        {
          "text": "运行",
          "link": "/quickstart/run"
        },
        {
          "text": "发布部署",
          "link": "/quickstart/release-deployment"
        },
        {
          "text": "API 调用",
          "link": "/quickstart/api"
        },
        {
          "text": "编译",
          "link": "/quickstart/compile"
        }
      ]
    },
    {
      "text": "项目",
      "items": [
        {
          "text": "项目类型",
          "link": "/project/types"
        },
        {
          "text": "Pipeline",
          "link": "/project/pipeline"
        },
        {
          "text": "KnowledgeBase",
          "link": "/project/knowledgebase"
        },
        {
          "text": "Agent",
          "link": "/project/agent"
        }
      ]
    },
    {
      "text": "我的部署",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples/"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    },
    {
      "text": "账单",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "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.