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

{
  "outline": [
    2,
    3
  ],
  "nav": [
    {
      "text": "Home",
      "link": "/"
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "miniSearch": {
        "options": {},
        "searchOptions": {}
      }
    }
  },
  "sidebar": [
    {
      "text": "欢迎",
      "link": "/"
    },
    {
      "text": "数值基础与伤害组成",
      "items": [
        {
          "text": "前置概念",
          "link": "/numeric/prologue"
        },
        {
          "text": "伤害组成",
          "link": "/numeric/damage"
        },
        {
          "text": "角色面板",
          "link": "/numeric/character"
        }
      ],
      "collapsed": false
    },
    {
      "text": "战力提升系统",
      "items": [
        {
          "text": "装备,超越与强化",
          "link": "/reinforcement/reinforcement"
        },
        {
          "text": "芯片",
          "link": "/reinforcement/chips"
        },
        {
          "text": "时装",
          "link": "/reinforcement/costume"
        },
        {
          "text": "重铸",
          "link": "/reinforcement/tuning"
        },
        {
          "text": "PNA",
          "link": "/reinforcement/pna"
        },
        {
          "text": "增益",
          "link": "/reinforcement/buff"
        }
      ],
      "collapsed": false
    },
    {
      "text": "副本基础信息",
      "link": "/region"
    },
    {
      "text": "刷图产出参考",
      "link": "/drops"
    },
    {
      "text": "分角色战斗指北(WIP)",
      "link": "/skills"
    },
    {
      "text": "装备制作指南(deprecated)",
      "link": "/equipments"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://gitlab.com/qzkszj/cls-docs-vitepress"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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