We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<template> <block> <view>{{request.loading}}</view> <view>{{request.data}}</view> <view>{{request.error}}</view> </block> </template> <script> export default { setup() { // 由于要保证request内部的变量不失活。 这里简单的可以将request直接抛出 const request = useRequest(getUsername); return { request, }; }, }; </script>
如果 data 是一个对象,那么使用起来会比较的 ugly, request.data.obj.a reqeust 目前是一个 reactive 对象,如果解构,那么就会失去响应式。能否把 request 定义成一个普通的对象,里面的 data loading 等值定义为 ref, 这样解构后,响应式依然存在。这样使用上也会和 react 版的一致。
data
request.data.obj.a
reqeust
reactive
request
loading
ref
react
可以参考 @tanstack/vue-query 的 API
// 其中 isPending, isError, data, error 都是 ref 类型的值 const { isPending, isError, data, error } = useQuery({ queryKey: ['todos'], queryFn: getTodos, })
The text was updated successfully, but these errors were encountered:
welcome discuss in wechat:
Sorry, something went wrong.
这个是因为内部需要用同样的 like react hooks 去完成一部分 hooks 的 shims. 其中 vue.ver 的
like react hooks
hooks
shims
vue.ver
useRef
taro-hooks/packages/plugin-vue/src/runtime/hooks.ts
Line 262 in a124393
和
useMemo
Line 243 in a124393
taro-hooks/packages/use-request/src/useRequestImplement.ts
Line 81 in a124393
(因为 instance 本身是一个 useMemo)
instance
Line 30 in a124393
都使用了 reactive 的方式去设计的. 如果要改的话可能会涉及到其他 hooks 的回归。
可以自己用 toRefs() 把 reactive 对象转换成键值为 ref 的对象然后用解构赋值
toRefs()
No branches or pull requests
如果
data
是一个对象,那么使用起来会比较的 ugly,request.data.obj.a
reqeust
目前是一个reactive
对象,如果解构,那么就会失去响应式。能否把request
定义成一个普通的对象,里面的data
loading
等值定义为ref
, 这样解构后,响应式依然存在。这样使用上也会和react
版的一致。Description
Solution
可以参考 @tanstack/vue-query 的 API
The text was updated successfully, but these errors were encountered: