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.png",
  "search": {
    "provider": "local"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "开发工具",
      "link": "/开发工具"
    },
    {
      "text": "前端",
      "link": "/frontend"
    },
    {
      "text": "后端",
      "link": "/后端"
    },
    {
      "text": "VitePress 1.6.3",
      "link": "https://vitepress.dev/zh/",
      "noIcon": true
    }
  ],
  "sidebar": [
    {
      "text": "database",
      "items": [
        {
          "text": "Redis",
          "link": "/database/Redis"
        },
        {
          "text": "mysql",
          "link": "/database/mysql"
        },
        {
          "text": "rabbitmq",
          "link": "/database/rabbitmq"
        }
      ],
      "collapsed": false
    },
    {
      "text": "devops",
      "items": [
        {
          "text": "Docker",
          "link": "/devops/Docker"
        }
      ],
      "collapsed": false
    },
    {
      "text": "frontend",
      "items": [
        {
          "text": "Axios",
          "link": "/frontend/Axios"
        },
        {
          "text": "pinia-vue存储库",
          "link": "/frontend/pinia-vue存储库"
        }
      ],
      "collapsed": false
    },
    {
      "text": "java",
      "items": [
        {
          "text": "Gateway",
          "link": "/java/Gateway"
        },
        {
          "text": "jwt令牌主动失效",
          "link": "/java/jwt令牌主动失效"
        },
        {
          "text": "mybatis-plus",
          "link": "/java/mybatis-plus"
        },
        {
          "text": "mybatis",
          "link": "/java/mybatis"
        },
        {
          "text": "nacos",
          "link": "/java/nacos"
        },
        {
          "text": "openfeign",
          "link": "/java/openfeign"
        },
        {
          "text": "seata",
          "link": "/java/seata"
        },
        {
          "text": "sentinel",
          "link": "/java/sentinel"
        },
        {
          "text": "springboot发送邮件",
          "link": "/java/springboot发送邮件"
        }
      ],
      "collapsed": false
    },
    {
      "text": "markdown",
      "items": [
        {
          "text": "api-examples",
          "link": "/markdown/api-examples"
        },
        {
          "text": "markdown-examples",
          "link": "/markdown/markdown-examples"
        },
        {
          "text": "markdown使用",
          "link": "/markdown/markdown使用"
        }
      ],
      "collapsed": false
    },
    {
      "text": "network",
      "items": [
        {
          "text": "cloudflare tunnel",
          "link": "/network/cloudflare tunnel"
        },
        {
          "text": "公网访问本地服务",
          "link": "/network/公网访问本地服务"
        },
        {
          "text": "开启SMTP服务",
          "link": "/network/开启SMTP服务"
        },
        {
          "text": "计算机网络",
          "link": "/network/计算机网络"
        }
      ],
      "collapsed": false
    },
    {
      "text": "system",
      "items": [
        {
          "text": "Tauri构建时下载Wix和NSIS失败问题",
          "link": "/system/Tauri构建时下载Wix和NSIS失败问题"
        },
        {
          "text": "rust使用MSVC最小安装",
          "link": "/system/rust使用MSVC最小安装"
        },
        {
          "text": "windows定时关机",
          "link": "/system/windows定时关机"
        }
      ],
      "collapsed": false
    },
    {
      "text": "tools",
      "items": [
        {
          "text": "Everything搜索",
          "link": "/tools/Everything搜索"
        },
        {
          "text": "apifox测试工具",
          "link": "/tools/apifox测试工具"
        },
        {
          "text": "cursor重置使用次数",
          "link": "/tools/cursor重置使用次数"
        },
        {
          "text": "git",
          "link": "/tools/git"
        },
        {
          "text": "onelight",
          "link": "/tools/onelight"
        },
        {
          "text": "openlist",
          "link": "/tools/openlist"
        },
        {
          "text": "shields.io标签",
          "link": "/tools/shields.io标签"
        },
        {
          "text": "我常用的VSCode插件",
          "link": "/tools/我常用的VSCode插件"
        }
      ],
      "collapsed": false
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/caolib"
    },
    {
      "icon": "qq",
      "link": "https://qm.qq.com/q/LyPOD3WeYY"
    },
    {
      "icon": "telegram",
      "link": "https://t.me/caolibt"
    },
    {
      "icon": "bilibili",
      "link": "https://space.bilibili.com/441126797"
    },
    {
      "icon": "gitlab",
      "link": "https://gitlab.com/clibin"
    }
  ],
  "outline": {
    "level": [
      2,
      6
    ],
    "label": "大纲"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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