© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
Is it possible to make the useAsyncData composable delay page rendering until the data is loaded - Nuxt
N
Nuxt
•
10mo ago
•
5 replies
pabloelsoso.
Is it possible to make the useAsyncData composable delay page rendering until the data is loaded
type UseBDRequest
=
{
param
?
: string
;
key
: string
;
methodKey
?
:
|
"page
"
|
"types
"
|
"type
"
|
"option
"
|
"options
"
|
"menu
"
|
"menus
"
|
"categories
"
|
"category
"
|
"assets
"
|
"asset
"
;
setMeta
?
: boolean
| null
;
canredirect404
?
: boolean
| null
;
}
;
export const useBDRequest
=
(
{
param
=
"
"
,
key
,
methodKey
=
"page
"
,
setMeta
= true
,
canredirect404
= true
,
}
: UseBDRequest
)
:
{ data
: Ref
<any
>
; pending
: Ref
<boolean
>
; error
: Ref
<any
>
}
=
>
{
const
{
$head
,
$api
}
= useNuxtApp
(
)
;
/
/ return useAsyncData
(key
,
(
)
=
>
$api
.mongo
methodKey
)
;
const
{ data
, pending
, error
}
= useAsyncData
(key
,
(
)
=
>
$api
.mongo
methodKey
)
;
watchEffect
(
(
)
=
>
{
if
(setMeta
&
& data
.value
?
.success
&
& data
.value
?
.data
)
{
const
{
meta
_title
=
"
"
,
meta
_description
=
"
"
,
meta
_keywords
=
"
"
,
meta
_og
=
{
}
,
name
=
"
"
,
noindex
= false
,
nofollow
= false
,
canonical
=
"
"
,
updated
_at
=
"
"
,
}
= data
.value
.data
;
useHead
(
$head
(
{
meta
_title
,
meta
_description
,
meta
_keywords
,
meta
_image
: meta
_og
?
.
[
"
o
g
:image
"
]
"
"
,
title
: name
,
noindex
,
nofollow
,
canonical
,
lastmodified
: updated
_at
,
}
)
)
;
}
if
(canredirect404
&
&
(error
.value
data
.value
?
.success
=
=
= false
)
)
{
navigateTo
(
"
/404
"
)
;
}
}
)
;
return
{ data
, pending
, error
}
;
}
;
Nuxt
Join
Nuxt Community Chat Server
31,641
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Recent Announcements
Similar Threads
Shareable custom useAsyncData composable
N
Nuxt / ❓・help
2y ago
how to delay queryContent until useContent data is available?
N
Nuxt / ❓・help
2y ago