getExample.md 1.71 KB

获取示例数据

OpenAPI Specification

openapi: 3.0.1
info:
  title: ''
  version: 1.0.0
paths:
  /srv/:
    get:
      summary: 获取示例数据
      description: 这是一个示例接口,展示如何编写 OpenAPI 文档
      tags:
        - 示例模块
      parameters:
        - name: a
          in: query
          description: action 参数
          required: false
          example: example_data
          schema:
            type: string
        - name: id
          in: query
          description: 数据ID
          required: true
          example: 123
          schema:
            type: integer
      responses:
        '200':
          description: 成功返回
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    description: 0=失败,1=成功
                  msg:
                    type: string
                    description: 错误信息
                  data:
                    type: object
                    properties:
                      id:
                        type: integer
                        description: 数据ID
                      name:
                        type: string
                        description: 名称
                      created_at:
                        type: string
                        description: 创建时间

使用示例

import { getExampleDataAPI } from '@/api/example'

const { code, data } = await getExampleDataAPI({ id: 123 })

if (code === 1) {
  console.log('成功:', data)
  console.log('数据ID:', data.id)
  console.log('名称:', data.name)
}