1个页面使用多个hook #666
1个页面使用多个hook
#666
-
解构时会报错,变量名冲突 const {data, loading, error} = useRequest(method1);
const {data, loading, error} = useWatcher(() => method2(), [...]); // 会报错 尝试不解构直接返回 UseHookExposure,但视图不更新,调用 data2 传入子组件 props 会出现 undefined(F12 看到请求确实发出去了) const hook2 = useWatcher(() => method2(), [...]);
const data2 = hook2.data as Ref<...>;
const loading2 = hook2.data as Ref<boolean>;
const error2 = hook2.error as Ref<Error | undefined>; 有没有什么办法解决? |
Beta Was this translation helpful? Give feedback.
Answered by
MeetinaXD
Apr 11, 2025
Replies: 1 comment
-
解构后重名即可 const { data: dataA, loading: loadingA, error: errorA } = useRequest(method1);
const { data: dataB, loading: loadingB, error: errorB } = useWatcher(() => method2(), [...]); // 会报错 不解构使用时视图不更新的原因是alova内有依赖收集,在首次渲染时未使用的导出不会被更新 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
FlyingOnion
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解构后重名即可
不解构使用时视图不更新的原因是alova内有依赖收集,在首次渲染时未使用的导出不会被更新