Releases
Release v1.0.0
Released on December 24, 2025
1.0.0 (2025-12-24)
⚠ BREAKING CHANGES
- api: useApiAuth 移除 logout() 和 refreshUser(),改用 nuxt-auth-utils 原生的 clear() 方法
- useApiFetch: UseApiFetchOptions 类型签名变更,移除 auth、onRequest 等钩子选项,认证由 api.factory 插件统一处理
- api: API 实例方法签名变更,不再提供 get/post/put/patch/delete 等方法,改用 $fetch 实例。
主要改动:
- useApiFetch 重构:基于 Nuxt 官方推荐的 Custom useFetch Recipe,使用自定义 $fetch 实例
- 新增 useClientApiFetch:仅客户端执行版本,设置
server: false+lazy: true - 响应处理分离:新增
api-helpers.ts工具,集中处理响应拦截、Toast 提示、数据解包、业务状态码检查 - ApiInstance 简化:移除 get/post/put/patch/delete 方法,仅保留 $fetch、use、download、upload、getConfig
- 模块声明修正:修复 module.ts 中
@nuxt/schema为nuxt/schema
技术细节:
- 在 $fetch 实例的
onResponse中检查业务状态码并抛出错误 - 使用
createApiResponseHandler创建响应处理器,传递给useFetch - 新增
skipBusinessCheck选项,允许跳过业务状态码检查 - 优化认证逻辑:提取
getTokenFromSession和handleUnauthorized - 优化 Toast 逻辑:统一
showToast函数,支持配置优先级合并
迁移指南:
// ❌ 旧方式
const { $api } = useNuxtApp()
const data = await $api.get('/users')
// ✅ 新方式
const { data } = await useApiFetch('/users')
// ✅ 或直接使用 $fetch
const { $api } = useNuxtApp()
const data = await $api.$fetch('/users')
✨ Features
- api: 添加自定义 API Fetch 框架 (419b575)
- api: 重构 useApiFetch 基于 useFetch 和自定义 $fetch 实例 (3bffbd8)
- auth: ✨ 增加 UserSession.token 类型并将 token 存储在 session 公开字段 (36ab58f)
- docs: 添加 Sandbox 嵌入式编辑器组件 (77fc3c4)
- playground: 添加 UseApiFetch 示例页面 (231e7bc)
- playground: 重构导航结构并新增 composables 示例页面 (bdddd20)
🐛 Bug Fixes
📝 Documentation
- api: 完善 useApiFetch 文档 (4c372c0)
- api: 添加 useApiFetch 使用文档 (ba6a62d)
- 删除过时的 API 文档和示例文件 (8d0db8d)
- 更新 CLAUDE.md 文档以反映最新架构 (94a6884)
- 添加示例文档章节 (2052cdd)
- 重构文档结构并新增 API 相关文档 (4185868)
♻️ Code Refactoring
- api: 简化 API 模块类型和认证流程 (b0c67e3)
- api: 重构 插件工厂 (720b78b)
- api: 重构 API 模块类型定义和 Schema (edf18ac)
- api: 重构 API 配置架构并新增上传下载组件 (f27096f)
- api: 重构 useApiFetch 基于 useAsyncData + $api (8776235)
- docs: 使用 @movk/nuxt-docs 内置 Vercel Analytics 配置 (5bfd0cd)
- schemas: ♻️ 使用 zod 默认值统一管理 API 模块配置 (0d6a807)
- test: 优化测试策略并清理 mock 文件 (6c057fe)
- test: 使用真实的 @movk/core 包替代 mock (895057b)
- useApiFetch: 重构 API 请求模块架构 (277ea7c)
✅ Tests
- 创建并修正 composables 全面测试用例 (ff33407), closes #components
- 新增 useApiFetch 单元测试和 vitest 配置 (1163257)