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": "/logo.svg",
  "nav": [
    {
      "text": "kucoder官网",
      "link": "http://kucoder.com"
    },
    {
      "text": "关于",
      "link": "/about"
    },
    {
      "text": "文档",
      "link": "/docs"
    },
    {
      "text": "资源",
      "link": "/resource"
    },
    {
      "text": "联系",
      "link": "/contact"
    },
    {
      "text": "下拉菜单",
      "items": [
        {
          "text": "Item A",
          "link": "/item-1"
        },
        {
          "text": "Item B",
          "link": "/item-2"
        },
        {
          "text": "Item C",
          "link": "/item-3"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "安装使用",
      "items": [
        {
          "text": "简介",
          "link": "/"
        },
        {
          "text": "系统安装",
          "link": "/install/install"
        },
        {
          "text": "项目结构",
          "link": "/install/project"
        },
        {
          "text": "项目声明",
          "link": "/install/statement"
        }
      ]
    },
    {
      "text": "后端文档",
      "items": [
        {
          "text": "配置文件",
          "link": "/backend/config"
        },
        {
          "text": "控制器",
          "link": "/backend/controller"
        },
        {
          "text": "模型",
          "link": "/backend/model"
        },
        {
          "text": "服务",
          "link": "/backend/service"
        },
        {
          "text": "数据库",
          "link": "/backend/database"
        },
        {
          "text": "其他",
          "link": "/backend/other"
        }
      ]
    },
    {
      "text": "插件市场",
      "items": [
        {
          "text": "插件市场",
          "link": "/plugin/desc"
        },
        {
          "text": "插件开发",
          "link": "/plugin/develop"
        },
        {
          "text": "实体类",
          "link": "/backend/entity"
        },
        {
          "text": "数据库",
          "link": "/backend/database"
        },
        {
          "text": "配置文件",
          "link": "/backend/config"
        },
        {
          "text": "其他",
          "link": "/backend/other"
        }
      ]
    },
    {
      "text": "前端(vue-kc-admin)",
      "items": [
        {
          "text": "组件",
          "link": "/frontend/component"
        },
        {
          "text": "路由",
          "link": "/frontend/router"
        },
        {
          "text": "状态管理",
          "link": "/frontend/store"
        },
        {
          "text": "其他",
          "link": "/frontend/other"
        }
      ]
    },
    {
      "text": "部署",
      "items": [
        {
          "text": "部署",
          "link": "/deploy/deploy"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/himfkc/kucoder"
    }
  ],
  "search": {
    "provider": "local"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "test/api-examples.md",
  "filePath": "test/api-examples.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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