refactor(http): 修改请求返回类型并处理业务逻辑错误

移除 IResData 包装层,直接返回数据部分。在 http 模块中添加业务逻辑错误处理,当 code 不为成功时抛出错误
This commit is contained in:
feige996
2025-09-14 21:02:32 +08:00
parent 1b9723e42a
commit b0e51ed39f
2 changed files with 11 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ interface IUseRequestReturn<T> {
* @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。
*/
export default function useRequest<T>(
func: () => Promise<IResData<T>>,
func: () => Promise<T>,
options: IUseRequestOptions<T> = { immediate: false },
): IUseRequestReturn<T> {
const loading = ref(false)
@@ -33,7 +33,7 @@ export default function useRequest<T>(
loading.value = true
return func()
.then((res) => {
data.value = res.data
data.value = res
error.value = false
return data.value
})