hooks icon indicating copy to clipboard operation
hooks copied to clipboard

当我使用ahooks 的 useRequest 时 报错--Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'then')

Open chenJJ-88 opened this issue 2 years ago • 7 comments

image image image 请问一下这个怎么处理呢????

chenJJ-88 avatar Oct 30 '23 09:10 chenJJ-88

options里面写onSuccess函数处理返回参数

Wang-yubo avatar Nov 03 '23 07:11 Wang-yubo

options里面写onSuccess函数处理返回参数

方便详细说一下吗,不是很理解你说的,这个和处理返回蚕食有什么问题呢

chenJJ-88 avatar Nov 06 '23 07:11 chenJJ-88

@chenJJ-88 请提供一个 demo 呢

crazylxr avatar Feb 27 '24 01:02 crazylxr

Hello @chenJJ-88. Please provide a online reproduction by forking this link https://codesandbox.io/s/ok2fe or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

你好 @chenJJ-88, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。

github-actions[bot] avatar Feb 27 '24 02:02 github-actions[bot]

image

看截图这个目录结构和文件名,感觉不像是 v3 的 ahooks,像是 v2 版本的。应该是用的这个包:https://www.npmjs.com/package/@ahooksjs/use-request

liuyib avatar Feb 27 '24 03:02 liuyib

楼主用了 v2 的这个用法:

https://ahooks-v2.js.org/zh-CN/hooks/async#%E9%9B%86%E6%88%90%E8%AF%B7%E6%B1%82%E5%BA%93

image

然后他的 service 传函数时,返回值出现了 undefined,导致:s.then 取值报错:

image

@chenJJ-88 你应该调整 service 函数的返回值,不能返回假值(null, undefined)

liuyib avatar Feb 27 '24 03:02 liuyib

另外 v2 已经不再维护,可以的话请升级最新版本

liuyib avatar Feb 27 '24 03:02 liuyib