Skip to content

运行时 API 示例 ​

本页展示了 VitePress 提供的一些运行时 API 的使用方法。

主要的 useData() API 可用于访问当前页面的站点、主题和页面数据。它在 .md 和 .vue 文件中均可使用:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## 结果

### 主题数据

<pre>{{ theme }}</pre>

### 页面数据

<pre>{{ page }}</pre>

### 页面 Frontmatter

<pre>{{ frontmatter }}</pre>

结果 ​

主题数据 ​

{
  "sidebarMenuLabel": "菜单",
  "returnToTopLabel": "返回顶部",
  "docFooter": {
    "prev": "上一页",
    "next": "下一页"
  },
  "darkModeSwitchLabel": "主题",
  "lightModeSwitchTitle": "切换到浅色模式",
  "darkModeSwitchTitle": "切换到深色模式",
  "langMenuLabel": "选择语言",
  "logo": {
    "src": "/img/logo.png"
  },
  "outline": {
    "level": "deep"
  },
  "nav": [
    {
      "text": "VMTU文档",
      "link": "/vmtu/"
    },
    {
      "text": "汉化准则",
      "link": "/rule/"
    },
    {
      "text": "教程",
      "items": [
        {
          "text": "整合包相关",
          "items": [
            {
              "text": "汉化补丁安装",
              "link": "/tutorial/modpack/translation"
            },
            {
              "text": "服务端下载",
              "link": "/tutorial/modpack/serverpack"
            }
          ]
        }
      ]
    },
    {
      "text": "VM官网",
      "link": "https://www.vmct.top/"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/VM-Chinese-translate-group"
    },
    {
      "icon": "bilibili",
      "link": "https://space.bilibili.com/3546956559288550"
    }
  ],
  "sidebar": [
    {
      "text": "VMTU文档",
      "collapsed": true,
      "base": "/vmtu/",
      "link": "/",
      "items": [
        {
          "text": "配置文件",
          "base": "/vmtu/configs/",
          "link": "/",
          "items": [
            {
              "text": "VM Metadata",
              "link": "metadata"
            },
            {
              "text": "ModpackInfo",
              "link": "modpackinfo"
            }
          ]
        },
        {
          "text": "语言",
          "link": "language"
        },
        {
          "text": "模组检测",
          "link": "mod-check"
        },
        {
          "text": "资源包",
          "link": "resourcepack"
        },
        {
          "text": "汉化更新检测",
          "link": "translation-update"
        }
      ]
    },
    {
      "text": "汉化准则",
      "collapsed": true,
      "base": "/rule/",
      "link": "/",
      "items": [
        {
          "text": "普适汉化准则",
          "link": "common"
        },
        {
          "text": "地图汉化准则",
          "link": "map"
        }
      ]
    },
    {
      "text": "教程",
      "collapsed": true,
      "base": "/tutorial/",
      "items": [
        {
          "text": "整合包相关",
          "base": "/tutorial/modpack/",
          "link": "/",
          "items": [
            {
              "text": "汉化补丁安装",
              "link": "translation"
            },
            {
              "text": "服务端下载",
              "link": "serverpack"
            }
          ]
        }
      ]
    },
    {
      "text": "工具链文档",
      "collapsed": true,
      "base": "/internal/",
      "items": [
        {
          "text": "创建新项目",
          "link": "new-project"
        }
      ]
    },
    {
      "text": "文档示例",
      "collapsed": true,
      "base": "/example/",
      "link": "/",
      "items": [
        {
          "text": "运行时 API 示例",
          "link": "api"
        },
        {
          "text": "特有组件示例",
          "link": "component"
        },
        {
          "text": "Markdown 示例",
          "link": "markdown"
        }
      ]
    }
  ],
  "search": {
    "provider": "local",
    "options": {
      "translations": {
        "button": {
          "buttonText": "搜索文档",
          "buttonAriaLabel": "搜索文档"
        }
      }
    }
  }
}

页面数据 ​

{
  "title": "运行时 API 示例",
  "description": "",
  "frontmatter": {
    "layout": "doc",
    "title": "运行时 API 示例",
    "outline": "deep",
    "showCopyDownload": false
  },
  "headers": [],
  "relativePath": "example/api.md",
  "filePath": "example/api.md"
}

页面 Frontmatter ​

{
  "layout": "doc",
  "title": "运行时 API 示例",
  "outline": "deep",
  "showCopyDownload": false
}

更多 ​

查看文档了解完整的运行时 API 列表。