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

{
  "outlineTitle": "大纲",
  "outline": [
    1,
    6
  ],
  "logo": "/电脑.svg",
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "学习笔记",
      "items": [
        {
          "text": "Python-guide",
          "link": "/python-guide/README"
        }
      ]
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        },
        "modal": {
          "noResultsText": "没有找到相关结果",
          "resetButtonTitle": "清楚查询结果",
          "footer": {
            "selectText": "选择",
            "navigateText": "切换"
          }
        }
      }
    }
  },
  "sidebar": [
    {
      "text": "Python中文指南",
      "items": [
        {
          "text": "第一章:安装运行",
          "items": [
            {
              "text": "1.1 【环境】快速安装 Python 解释器",
              "link": "/python-guide/c01_01"
            },
            {
              "text": "1.2 【环境】Python 开发环境的搭建",
              "link": "/python-guide/c01_02"
            },
            {
              "text": "1.3 【基础】两种运行 Python 程序方法",
              "link": "/python-guide/c01_03"
            }
          ]
        },
        {
          "text": "第二章:数据类型",
          "items": [
            {
              "text": "2.1 【基础】常量与变量",
              "link": "/python-guide/c02_01"
            },
            {
              "text": "2.2 【基础】字符串类型",
              "link": "/python-guide/c02_02"
            },
            {
              "text": "2.3 【基础】整数与浮点数",
              "link": "/python-guide/c02_03"
            },
            {
              "text": "2.4 【基础】布尔值:真与假",
              "link": "/python-guide/c02_04"
            },
            {
              "text": "2.5 【基础】学会输入与输出",
              "link": "/python-guide/c02_05"
            },
            {
              "text": "2.6 【基础】字符串格式化",
              "link": "/python-guide/c02_06"
            },
            {
              "text": "2.7 【基础】运算符(超全整理)",
              "link": "/python-guide/c02_07"
            }
          ]
        },
        {
          "text": "第三章:数据结构",
          "items": [
            {
              "text": "3.1 【基础】列表",
              "link": "/python-guide/c03_01"
            },
            {
              "text": "3.2 【基础】元组",
              "link": "/python-guide/c03_02"
            },
            {
              "text": "3.3 【基础】字典",
              "link": "/python-guide/c03_03"
            },
            {
              "text": "3.4 【基础】集合",
              "link": "/python-guide/c03_04"
            },
            {
              "text": "3.5 【基础】迭代器",
              "link": "/python-guide/c03_05"
            },
            {
              "text": "3.6 【基础】生成器",
              "link": "/python-guide/c03_06"
            }
          ]
        },
        {
          "text": "第四章:控制流程",
          "items": [
            {
              "text": "4.1 【基础】条件语句:if",
              "link": "/python-guide/c04_01"
            },
            {
              "text": "4.2 【基础】循环语句:for",
              "link": "/python-guide/c04_02"
            },
            {
              "text": "4.3 【基础】循环语句:while",
              "link": "/python-guide/c04_03"
            },
            {
              "text": "4.4 【进阶】五种推导式",
              "link": "/python-guide/c04_04"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/lwr971203"
    }
  ],
  "footer": {
    "copyright": "这是一个版权声明"
  }
}

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.