Skip to content

ApiDoc API 文档组件

支持 API 接口展示、请求参数、curl 示例的文档组件。

基础用法

API 端点
GET/users
POST/users
GEThttps://api.example.com/users获取用户列表
请求参数
参数名类型必填默认值说明
pagenumber可选1页码
limitnumber可选10每页数量
curl 示例
curl -X GET 'https://api.example.com/users' -H 'Authorization: ApiKey YOUR_API_KEY'
响应示例
{"data": [], "total": 100}
vue
<template>
  <x-api-doc
    :base-url="'https://api.example.com'"
    :endpoints="endpoints"
    :show-curl-example="true"
    :auth-type="'apikey'"
  />
</template>

<script setup>
import { ApiDoc } from '@xto/business'

const endpoints = [
  {
    method: 'GET',
    path: '/users',
    description: '获取用户列表',
    parameters: [
      { name: 'page', type: 'number', required: false, description: '页码' }
    ],
    responseExample: '{"data": [], "total": 100}'
  },
  {
    method: 'POST',
    path: '/users',
    description: '创建用户',
    requestBody: '{"name": "张三"}'
  }
]
</script>

认证方式

支持多种认证方式配置。

vue
<template>
  <!-- API Key 认证 -->
  <x-api-doc auth-type="apikey" api-key-placeholder="YOUR_API_KEY" />

  <!-- Bearer Token 认证 -->
  <x-api-doc auth-type="bearer" api-key-placeholder="YOUR_TOKEN" />

  <!-- Basic 认证 -->
  <x-api-doc auth-type="basic" />

  <!-- 无认证 -->
  <x-api-doc auth-type="none" />
</template>

API

Props

属性说明类型默认值
baseUrlAPI 基础地址string'https://api.example.com'
endpointsAPI 端点列表ApiEndpoint[][]
showCurlExample是否显示 curl 示例booleantrue
authType认证方式'apikey' | 'bearer' | 'basic' | 'none''apikey'
apiKeyPlaceholderAPI Key 占位符string'YOUR_API_KEY'

ApiEndpoint

属性说明类型
methodHTTP 方法'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
pathAPI 路径string
description接口描述string
parameters请求参数列表ApiParameter[]
requestBody请求体示例string
responseExample响应示例string

ApiParameter

属性说明类型
name参数名称string
type参数类型string
required是否必填boolean
description参数说明string
defaultValue默认值string

Events

事件名说明
copy-curl复制 curl 命令时触发

基于 MIT 许可发布