Skip to content
山不让尘,川不辞盈
搜索 K
Main Navigation 主页闲聊关于
实用网页
工具插件

Appearance

Sidebar Navigation

pages

实用网页

工具插件

闲聊

关于我

2024

api examples

2023

markdown examples

On this page

Runtime API Examples ​

阅读时间:

1

分钟
文章字数:

118

字
发布日期:

2024-11-12

最近更新:

2024-11-19

api

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": "闲聊",
      "link": "/pages/comment"
    },
    {
      "text": "关于",
      "link": "/pages/about"
    },
    {
      "text": "推荐",
      "items": [
        {
          "items": [
            {
              "text": "实用网页",
              "link": "/pages/webPage"
            },
            {
              "text": "工具插件",
              "link": "/pages/tools"
            }
          ]
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "pages",
      "items": [
        {
          "text": "实用网页",
          "link": "/pages/webPage"
        },
        {
          "text": "工具插件",
          "link": "/pages/tools"
        },
        {
          "text": "闲聊",
          "link": "/pages/comment"
        },
        {
          "text": "关于我",
          "link": "/pages/about"
        }
      ],
      "collapsed": false
    },
    {
      "text": "2024",
      "items": [
        {
          "text": "api examples",
          "link": "/2024/api-examples"
        }
      ],
      "collapsed": false
    },
    {
      "text": "2023",
      "items": [
        {
          "text": "markdown examples",
          "link": "/2023/markdown-examples"
        }
      ],
      "collapsed": false
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/lee-holden/vitepress-blog-template"
    }
  ]
}

Page Data ​

{
  "title": "api examples",
  "description": "",
  "frontmatter": {
    "outline": "deep",
    "title": "api examples",
    "date": "2024-11-12T00:00:00.000Z",
    "info": "api测试",
    "tags": [
      "api"
    ]
  },
  "headers": [],
  "relativePath": "2024/api-examples.md",
  "filePath": "2024/api-examples.md"
}

Page Frontmatter ​

{
  "outline": "deep",
  "title": "api examples",
  "date": "2024-11-12T00:00:00.000Z",
  "info": "api测试",
  "tags": [
    "api"
  ]
}

More ​

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

1 ​

123

2 ​

123

3 ​

123

Pager
Previous page关于我
Next pagemarkdown examples
本站总访问量 -- 次 本站访客数 -- 人次

前端狗都不如 © 2021-2024 holden