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

{
  "nav": [
    {
      "text": "首页",
      "link": "/"
    },
    {
      "text": "ngrok",
      "link": "https://ngrok.cn/ngrok.html"
    },
    {
      "text": "vitepress",
      "link": "https://ngrok.cn/vitepress/"
    },
    {
      "text": "HTML",
      "link": "https://ngrok.cn/html/html-html-tutorial.html"
    },
    {
      "text": "css",
      "link": "https://ngrok.cn/css/css-css-tutorial.html"
    },
    {
      "text": "javascript",
      "link": "https://ngrok.cn/javascript/javascript-js-intro.html"
    },
    {
      "text": "VUE3",
      "link": "https://ngrok.cn/vue3/introduction.html"
    },
    {
      "text": "redis",
      "link": "https://ngrok.cn/redis/redis-redis-intro.html"
    },
    {
      "text": "es6",
      "link": "https://ngrok.cn/es6/escript6-escript6-jianjie.html"
    }
  ],
  "sidebar": [
    {
      "text": "Examples",
      "items": []
    }
  ],
  "footer": {
    "message": "ngrok中文网声明:本网教程均来源于技术官网或其他技术网站整理,版权归技术官网或其他整理者所有",
    "copyright": "Copyright © 2016-2024 present ngrok.cn;备案号:<a href=\"https://beian.miit.gov.cn/\" target=\"_blank\">浙ICP备14031531号-2</a>"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://wenwuyi.cn"
    }
  ]
}

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.

ngrok中文网声明:本网教程均来源于技术官网或其他技术网站整理,版权归技术官网或其他整理者所有