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

{
  "i18nRouting": false,
  "logo": "/logo.png",
  "nav": [
    {
      "text": "导航",
      "link": "/nav/"
    },
    {
      "text": "源码阅读",
      "link": "/codeReading/"
    },
    {
      "text": "踩坑记录",
      "link": "/problem/"
    },
    {
      "text": "个人笔记",
      "link": "https://github.com/LittleTangJF/my_note"
    }
  ],
  "sidebar": {},
  "outline": {
    "level": "deep",
    "label": "本页目录"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/LittleTangJF/vitepress-blog"
    }
  ],
  "footer": {
    "message": "如有转载或 CV 的请标注本站原文地址",
    "copyright": "Copyright © 2019-present "
  },
  "darkModeSwitchLabel": "外观",
  "returnToTopLabel": "返回顶部",
  "lastUpdatedText": "上次更新",
  "docFooter": {
    "prev": "上一篇",
    "next": "下一篇"
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "codeReading/index.md",
  "lastUpdated": 1680347487000
}

Page Frontmatter

{
  "outline": "deep"
}

More

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

上次更新:

如有转载或 CV 的请标注本站原文地址