[RESOLVED] I need await on start up of app.vue
I would like to wait until it has finished loading all the essential data to be able to proceed with using the application, what is the best practice?
I'm currently using a plugin and until it enters onMounted the layout and page aren't shown.
42 Replies
Would do it the same way but with a loading indicator/page. But there has to be a nicer way. Curious how other people would do it.
Can hooks events be stopped?
with async/await
I usually opt for an asynchronous middleware. This blocks the app from loading until the promise has been resolved
uhm okay, but how do you understand that it only needs to charge once? Middleware are the routes and they are triggered every time the page is changed.
Yon can combine that with a cookie or a global state. So you only call/await the async function when the state holds a certain value (you decide what the value is)
But you will get a blank page till everything is loaded right?
Yes
That’s what happens on initial page load. Subsequent page navigations using the same middleware - if the await call is not skipped - will just block the navigation until the middleware has finished running
I honestly don't like this solution, it seems like the connection is slow or network problems
that's fine. it was only a suggestion
PS: if you're fetching the data from an external API, you can only but wait. Add a loading screen for wait time would improve the UX nonetheless
I appreciate your suggestion thanks.
I also did this in app.vue but I got the warning saying that I have some pages and I don't have the <NuxtPage> tag just because it was hidden at a certain time.
are you rendering the NuxtPage conditionally?
yah, look at the first comment I made
the condition there is on the layout
yes, because I don't want to see the layout too
try this. should help clear the error
not work.
my code now is:
no, not on the template
the layout is wrapped in a div that's has the condition
same error also with div
strange
there is also this warn:
i just tested with this and it worked fine
how you defined pages and layouts?
I don't follow
can u rephrase?
try create one page and one layout
I have 2 layouts and several pages
i'm on nuxt v3.11.1
uhm, very strange....
I used <slot> on layout, it's correct ?
me too
yeah. same
wait, is that the only child inside the layout?
what mean?
what does your layout look like. then content of layout's template
nevermind. doesn't really matter
This is my layout for default and login (without component bar). I have two layouts
one moment
hmm. looks fine. not sure why you're getting that error
GitHub
Warning from NuxtLayout: Your project has layouts but the `` compon...
Environment package.json { "nuxt": "^3.9.0", "typescript": "^5.2.2", "vue": "3.4.0-rc.3", "vue-router": "latest" } Re...
in my opinion it would have been very useful to somehow stop the client process in the hook for a moment
I read thanks
in the documentation there is this:
But let's return to the same problem which must be put in middleware and seems to be the effect of the internet slowdown
yeah. that helps greatly when you're using a middleware
Something like this doesn’t work?
I think that this is correct but the problem is display on console one warning of NuxtPage
Mhh
Not sure if you can hide the nuxtpage at first
Stack Overflow
How to add a page loader in Nuxt 3 application
I’m building an application using Nuxt 3, I want to add a page loader until the website loads.
It's okay to remove the loading animation but that's not what I need.
Apparently only what I did works, that is, creating an asynchronous plugin and as long as app.vue enters onMounted it means that it has loaded all the plugins.
Currently the most effective solution without having warnings for NuxtPage is to set the #__nuxt style as display: none; and when onMounted of app.vue enters I set #__nuxt as display: block;
Thanks guys so much for helping me.
ahh the simplicity 👌