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

{
  "lang": "zh-CN",
  "lastUpdated": {
    "text": "Updated at"
  },
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "Java",
      "link": "/Java/"
    },
    {
      "text": "Spring",
      "link": "/Spring/"
    },
    {
      "text": "Elasticsearch",
      "link": "/ES/"
    },
    {
      "text": "Linux",
      "link": "/Linux/"
    },
    {
      "text": "Mysql",
      "link": "/Mysql/"
    },
    {
      "text": "Redis",
      "link": "/Redis/"
    },
    {
      "text": "其他",
      "items": [
        {
          "text": "Nacos",
          "link": "/Nacos/"
        },
        {
          "text": "Nginx",
          "link": "/Nginx/"
        },
        {
          "text": "Docker",
          "link": "/Docker/"
        },
        {
          "text": "Others",
          "link": "/Other/"
        }
      ]
    }
  ],
  "sidebar": {
    "/Docker/": [
      {
        "items": []
      }
    ],
    "/ES/": [
      {
        "items": [
          {
            "text": "ES集群相关",
            "link": "/ES/ES集群相关.html"
          },
          {
            "text": "Elasticsearch 实战篇 如何选择合适的ES存储集群",
            "link": "/ES/Elasticsearch 实战篇 如何选择合适的ES存储集群.html"
          }
        ]
      }
    ],
    "/Java/": [
      {
        "items": []
      }
    ],
    "/Linux/": [
      {
        "items": [
          {
            "text": "未命名",
            "link": "/Linux/未命名.html"
          }
        ]
      }
    ],
    "/Mac/": [
      {
        "items": [
          {
            "text": "查找文件夹并删除",
            "link": "/Mac/查找文件夹并删除.html"
          }
        ]
      }
    ],
    "/Mysql/": [
      {
        "items": []
      }
    ],
    "/Nacos/": [
      {
        "items": [
          {
            "text": "Nacos源码在项目中启动使用",
            "link": "/Nacos/Nacos源码在项目中启动使用.html"
          }
        ]
      }
    ],
    "/Nginx/": [
      {
        "items": [
          {
            "text": "Vue前端部署配置",
            "link": "/Nginx/Vue前端部署配置.html"
          },
          {
            "text": "后端API部署配置",
            "link": "/Nginx/后端API部署配置.html"
          }
        ]
      }
    ],
    "/Other/": [
      {
        "items": []
      }
    ],
    "/Redis/": [
      {
        "items": []
      }
    ],
    "/Spring/": [
      {
        "items": [
          {
            "text": "SpringBoot",
            "items": [
              {
                "text": "springboot初始化bean(扫描自定义注解)",
                "link": "/Spring/SpringBoot/springboot初始化bean(扫描自定义注解).html"
              }
            ],
            "collapsed": false
          }
        ]
      }
    ],
    "/临时文件/": [
      {
        "items": []
      }
    ],
    "/基础项目/": [
      {
        "items": [
          {
            "text": "archetype-20.0",
            "link": "/基础项目/archetype-2.0.0.html"
          }
        ]
      }
    ],
    "/待研究/": [
      {
        "items": []
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "http://www.daydaynote.cn"
    }
  ],
  "footer": {
    "message": "<a href=\"https://beian.miit.gov.cn/\">蜀ICP备18003120号-1</a>",
    "copyright": "Copyright©2020-2024 <a href=\"http://www.daydaynote.cn\">Daydaynote.cn</a>"
  },
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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