压缩专家
43.99M · 2026-04-01
// 读操作示例
import { requestRead } from './axios/basic/axios'
const response = await requestRead({
method: 'get',
url: '/api/users',
data: { page: 1, pageSize: 10 }
})
// 写操作示例
import { requestWrite } from './axios/basic/axios'
const response = await requestWrite({
method: 'post',
url: '/api/users',
data: { name: 'John', age: 30 }
})
EndpointConfig 类标准化 API 端点配置request 方法,支持缓存、错误处理等高级功能EndpointConfig:API 端点配置类,用于创建标准化的 API 端点配置ApiBase:API 基础抽象类,提供通用的 API 操作方法// 1. 定义 API 端点配置
const userEndpoints: IBaseApiEndpoints = {
list: new EndpointConfig('/api/users', {
method: 'get',
requestType: 'read',
cacheable: true
}),
add: new EndpointConfig('/api/users', {
method: 'post',
requestType: 'write'
}),
// 其他端点配置...
}
// 2. 创建 API 实例
class UserApi extends ApiBase {
constructor() {
super(userEndpoints)
}
}
// 3. 使用 API 实例
const userApi = new UserApi()
// 获取用户列表
const users = await userApi.list({ page: 1, pageSize: 10 })
// 添加新用户
await userApi.add({ name: 'John', email: 'john@example.com' })
// 更新用户信息
await userApi.update(1, { name: 'John Doe' })
// 删除用户
await userApi.delete([1, 2, 3])
// 获取用户详情
const user = await userApi.getById(1)
欢迎下载源码 使用,如觉得有用麻烦您点个赞。