为什么Uselazyfetch综合返回null数据?
我正在尝试学习如何在NUXT3中使用数据获取组合。 由于某种原因,我得到了一个“加载”文本,以代替用户名应为:
我的预期输出应该是:
这是我的可综合代码:
USEUSER
:
export default function (id) {
const baseURL = 'https://jsonplaceholder.typicode.com';
const { pending: pendingUsers, data: users } = useLazyFetch(
`${baseURL}/users`
);
const { pending: pendingUser, data: user } = useLazyFetch(
`${baseURL}/users/${id}`
);
return {
pendingUsers,
users,
pendingUser,
user,
};
}
以及我想使用的组件在这里:
pcardcard.vue
:
<template>
<article class="rounded border overflow-hidden">
...snip...
<footer class="mt-6 flex items-center">
<PostAvatar :post="post" />
<div class="ml-3">
<p class="text-sm font-medium text-gray-900">
<a href="#" class="hover:underline">
{{ pendingUser ? 'Loading...' : user.name }} /////<---- HERE!
</a>
</p>
<div class="flex space-x-1 text-sm text-gray-500">
<!-- <time :datetime="post.datetime">
{{ post.date }}
</time> -->
mar 4, 2019
<span aria-hidden="true">·</span>
<span>misc</span>
</div>
</div>
</footer>
...snip...
</article>
</template>
<script setup>
const props = defineProps({
post: {
type: Object,
default: () => ({}),
},
});
const { pendingUser, user } = useUser(props.post.userId);
</script>
有人知道为什么用户名不加载吗?如果i console.log(pendinguser.value,user.value)
我获得 true null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新
不确定是否是实际的当前问题,但将
nuxt
降级到3.0.0.0-rc.1
修复了问题。给定此组合
/composables/useuser.js
,此视图
/pages/index.vue
您应该有一些工作。
如手表(不确定)(不确定)(不确定) “ nofollow noreferrer”>文档因为
uselazyfetch
是异步和非块。Update
Not sure if it's an actual current issue but downgrading
nuxt
to3.0.0-rc.1
fixed the issue.Given this composable
/composables/useUser.js
And this view
/pages/index.vue
You should have something working.
The usage of
watch
may be needed (not sure) as explained in the documentation becauseuseLazyFetch
is async and non-blocking.