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": "/logoYian.png",
  "siteTitle": false,
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "全部文章",
      "link": "/articles/"
    },
    {
      "text": "笔记分类",
      "items": [
        {
          "text": "编程语言",
          "link": "/articles/programlang"
        },
        {
          "text": "学习",
          "link": "/articles/learning/"
        },
        {
          "text": "技术",
          "link": "/articles/technology"
        }
      ]
    },
    {
      "text": "返回导航页",
      "link": "https://yianaux.top/"
    }
  ],
  "sidebar": {
    "/articles/": [
      {
        "text": "全部文章",
        "items": [
          {
            "text": "Artificial Intelligence",
            "collapsible": true,
            "collapsed": true,
            "link": "/articles/artificial-intelligence/",
            "items": [
              {
                "text": "KAN",
                "link": "/articles/artificial-intelligence/AN",
                "items": [
                  {
                    "text": "KAN",
                    "link": "/articles/artificial-intelligence/KAN/kAN"
                  }
                ]
              },
              {
                "text": "Transformer",
                "link": "/articles/artificial-intelligence/transformer",
                "items": [
                  {
                    "text": "QKV注意力",
                    "link": "/articles/artificial-intelligence/transformer/QKV"
                  },
                  {
                    "text": "Transformer结构",
                    "link": "/articles/artificial-intelligence/transformer/transformers"
                  },
                  {
                    "text": "Vit",
                    "link": "/articles/artificial-intelligence/transformer/vit"
                  }
                ]
              }
            ]
          },
          {
            "text": "Front End",
            "link": "/articles/front-end/"
          },
          {
            "text": "Pyqt5",
            "link": "/articles/pyqt5/"
          }
        ]
      }
    ],
    "/articles/programlang/": [
      {
        "text": "Programming Language",
        "base": "/articles/programlang/",
        "items": [
          {
            "text": "C&C++",
            "collapsible": true,
            "collapsed": true,
            "base": "/articles/programlang/C&C++/",
            "items": [
              {
                "text": "4.4虚类",
                "link": "4.4虚类"
              },
              {
                "text": "4.5基类与公有派生类对象的赋值兼容",
                "link": "4.5基类与公有派生类对象的赋值兼容"
              }
            ]
          },
          {
            "text": "Python",
            "base": "/articles/programlang/python"
          },
          {
            "text": "Java",
            "base": "/articles/programlang/java"
          },
          {
            "text": "JavaScript",
            "base": "/articles/programlang/Javascript"
          },
          {
            "text": "vue",
            "base": "/articles/programlang/vue"
          }
        ]
      }
    ],
    "/articles/learning/": [
      {
        "text": "Learning",
        "base": "/articles/learning/",
        "items": [
          {
            "text": "Artificial Intelligence",
            "base": "/articles/learning/artificial-intelligence",
            "collapsible": true,
            "collapsed": true,
            "items": [
              {
                "text": "KAN",
                "base": "/articles/learning/artificial-intelligence/KAN",
                "collapsible": true,
                "collapsed": true,
                "items": [
                  {
                    "text": "KAN",
                    "link": "/kAN"
                  }
                ]
              },
              {
                "text": "Transformer",
                "base": "/articles/learning/artificial-intelligence/transformer",
                "collapsible": true,
                "collapsed": true,
                "items": [
                  {
                    "text": "QKV注意力",
                    "link": "/QKV"
                  },
                  {
                    "text": "Transformer结构",
                    "link": "/transformer"
                  },
                  {
                    "text": "Vit",
                    "link": "/vit"
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "/articles/technology/": [
      {
        "text": "Technology",
        "base": "/articles/technology",
        "items": [
          {
            "text": "4_19面向对象_工厂模式与单例模式",
            "link": "/4_19面向对象_工厂模式与单例模式"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/NAOXUAN4"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Copyright © 2024-Yian🥰"
  },
  "search": {
    "provider": "local"
  }
}

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.

Released under the MIT License.