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": [
    2,
    6
  ],
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "前端",
      "items": [
        {
          "text": "Vue",
          "link": "/frontend/vue/index"
        },
        {
          "text": "iOS",
          "link": "/frontend/ios/index"
        }
      ]
    },
    {
      "text": "语言",
      "items": [
        {
          "text": "js",
          "link": "/frontend/js/index"
        },
        {
          "text": "swift",
          "link": "/frontend/swift/index"
        }
      ]
    },
    {
      "text": "工程化",
      "link": "/engineering"
    },
    {
      "text": "后端",
      "link": "/backend/container/tomcat"
    },
    {
      "text": "网络",
      "link": "/network"
    },
    {
      "text": "Examples",
      "link": "/guide/markdown-examples"
    }
  ],
  "sidebar": {
    "/frontend/vue": [
      {
        "text": "Vue",
        "items": []
      }
    ],
    "/frontend/js": [
      {
        "text": "JS",
        "items": []
      }
    ],
    "/frontend/base": [
      {
        "text": "基础",
        "items": [
          {
            "text": "xml-tips",
            "link": "frontend/base/xml-tips.md"
          }
        ]
      },
      {
        "text": "其他",
        "items": [
          {
            "text": "2020-03-12-ionic",
            "link": "frontend/other/2020-03-12-ionic.md"
          },
          {
            "text": "2020-03-22-angular",
            "link": "frontend/other/2020-03-22-angular.md"
          }
        ]
      }
    ],
    "/frontend/ios": [
      {
        "text": "iOS",
        "items": [
          {
            "text": "apple-update-cert",
            "link": "frontend/ios/apple-update-cert.md"
          },
          {
            "text": "appstore-share",
            "link": "frontend/ios/appstore-share.md"
          },
          {
            "text": "autoPackage-tips",
            "link": "frontend/ios/autoPackage-tips.md"
          },
          {
            "text": "cocoapods",
            "link": "frontend/ios/cocoapods.md"
          },
          {
            "text": "download-share",
            "link": "frontend/ios/download-share.md"
          },
          {
            "text": "flutter",
            "link": "frontend/ios/flutter.md"
          },
          {
            "text": "framework-share",
            "link": "frontend/ios/framework-share.md"
          },
          {
            "text": "get-ipa",
            "link": "frontend/ios/get-ipa.md"
          },
          {
            "text": "im-first",
            "link": "frontend/ios/im-first.md"
          },
          {
            "text": "image-on-iphone",
            "link": "frontend/ios/image-on-iphone.md"
          },
          {
            "text": "jailbreak",
            "link": "frontend/ios/jailbreak.md"
          },
          {
            "text": "lock-share",
            "link": "frontend/ios/lock-share.md"
          },
          {
            "text": "macro-define",
            "link": "frontend/ios/macro-define.md"
          },
          {
            "text": "network-share",
            "link": "frontend/ios/network-share.md"
          },
          {
            "text": "note-share",
            "link": "frontend/ios/note-share.md"
          },
          {
            "text": "post-current-controller",
            "link": "frontend/ios/post-current-controller.md"
          },
          {
            "text": "post-dispatch-group",
            "link": "frontend/ios/post-dispatch-group.md"
          },
          {
            "text": "post-facebook-share",
            "link": "frontend/ios/post-facebook-share.md"
          },
          {
            "text": "post-instagram-share",
            "link": "frontend/ios/post-instagram-share.md"
          },
          {
            "text": "post-twitter-share",
            "link": "frontend/ios/post-twitter-share.md"
          },
          {
            "text": "post-view-tips",
            "link": "frontend/ios/post-view-tips.md"
          },
          {
            "text": "post-whatsapp-share",
            "link": "frontend/ios/post-whatsapp-share.md"
          },
          {
            "text": "reactnative",
            "link": "frontend/ios/reactnative.md"
          },
          {
            "text": "url-codeing",
            "link": "frontend/ios/url-codeing.md"
          },
          {
            "text": "version-share",
            "link": "frontend/ios/version-share.md"
          },
          {
            "text": "webScoket",
            "link": "frontend/ios/webScoket.md"
          },
          {
            "text": "webview-share",
            "link": "frontend/ios/webview-share.md"
          },
          {
            "text": "xcode build",
            "link": "frontend/ios/xcode build.md"
          }
        ]
      }
    ],
    "/frontend/swift": [
      {
        "text": "swift",
        "items": [
          {
            "text": "01-Getting Started",
            "collapsible": true,
            "items": [
              {
                "text": "Basic Setup",
                "link": "frontend/swift/01-Getting Started/Basic Setup.md"
              }
            ]
          },
          {
            "text": "02-Interoperability",
            "collapsible": true,
            "items": [
              {
                "text": "01-Interacting with Objective-C APIs",
                "link": "frontend/swift/02-Interoperability/01-Interacting with Objective-C APIs.md"
              },
              {
                "text": "02-Writing Swift Classes and Protocols with Objective-C Behavior",
                "link": "frontend/swift/02-Interoperability/02-Writing Swift Classes and Protocols with Objective-C Behavior.md"
              },
              {
                "text": "03-Working with Cocoa Frameworks",
                "link": "frontend/swift/02-Interoperability/03-Working with Cocoa Frameworks.md"
              },
              {
                "text": "04-Adopting Cocoa Design Patterns",
                "link": "frontend/swift/02-Interoperability/04-Adopting Cocoa Design Patterns.md"
              },
              {
                "text": "05-Interacting with C APIs",
                "link": "frontend/swift/02-Interoperability/05-Interacting with C APIs.md"
              }
            ]
          },
          {
            "text": "03-Mix and Match",
            "collapsible": true,
            "items": [
              {
                "text": "Swift and Objective-C in the Same Project",
                "link": "frontend/swift/03-Mix and Match/Swift and Objective-C in the Same Project.md"
              }
            ]
          },
          {
            "text": "04-Migration",
            "collapsible": true,
            "items": [
              {
                "text": "Migrating Your Objective-C Code to Swift",
                "link": "frontend/swift/04-Migration/Migrating Your Objective-C Code to Swift.md"
              }
            ]
          }
        ]
      }
    ],
    "/utils": [
      {
        "text": "工具",
        "items": [
          {
            "text": "Xcode 使用小技巧",
            "link": "/utils/2016-03-28-post-xcode-tips.md"
          },
          {
            "text": "Xcode 使用小技巧",
            "link": "/utils/2017-03-28-post-xcode-tips.md"
          },
          {
            "text": "Git 技巧",
            "link": "/utils/2019-04-15-git-comment.md"
          }
        ]
      }
    ],
    "/guide": [
      {
        "text": "Markdown 介绍",
        "items": [
          {
            "text": "Markdown 基础语法",
            "link": "/guide/markdown"
          },
          {
            "text": "Markdown 扩展语法",
            "link": "/guide/markdown-extension"
          },
          {
            "text": "Markdown 样例",
            "link": "/guide/markdown-examples"
          },
          {
            "text": "api 样例",
            "link": "/guide/api-examples"
          }
        ]
      }
    ],
    "/network": [
      {
        "text": "网络",
        "items": [
          {
            "text": "http网络请求",
            "link": "/network/https-tips"
          }
        ]
      }
    ],
    "/engineering": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/api-examples"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/feipages"
    },
    {
      "icon": "github",
      "link": "/guide/profile"
    }
  ],
  "footer": {
    "copyright": "Copyright © 2017-present Gao Fei",
    "message": "Released under the MIT License."
  },
  "search": {
    "provider": "local",
    "options": {
      "locales": {
        "root": {
          "translations": {
            "button": {
              "buttonText": "搜索文档",
              "buttonAriaLabel": "搜索文档"
            },
            "modal": {
              "noResultsText": "无法找到相关结果",
              "resetButtonTitle": "清除查询条件",
              "footer": {
                "selectText": "选择",
                "navigateText": "切换",
                "closeText": "关闭"
              }
            }
          }
        }
      }
    }
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.