A
A
Andrey Chirkov2021-07-02 14:55:54
JavaScript
Andrey Chirkov, 2021-07-02 14:55:54

What is the advantage of using asyncData in NUXT on pages, instead of processing in hooks (like async beforeMount)?

Reading the documentation and various answers, I still did not understand the differences, except that with asyncData it is very easy to show the loading bar on top. Tell me what exactly is better? You can also declare variables in the date and in the beforeMount or mount hooks, call axios and write the value to the variable.
Also, through asyncData, it was not entirely obvious how to embed a loader (essentially a variable in data)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-07-02
@andreichirkov

Until asyncData completes, the component will not be rendered or zapped.
With the standard approach, the component first renders a stub, then loads the data, then renders something based on the data, with asyncData it does nothing until there is data. It is more comfortable.
Alas, asyncData is not ideal, due to the architecture of vue-router (I once deeply understood, alas, without a complete rewriting of vue-router you can’t do much better), but it’s still more convenient than doing the same by hand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question