vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.24k stars 8.26k forks source link

async clientPrefetch hook - analog of serverPrefetch, waiting for data loaded on client #6509

Open boogiefromzk opened 2 years ago

boogiefromzk commented 2 years ago

What problem does this feature solve?

Here are discussions: https://github.com/vuejs/vue-router/issues/1144 https://github.com/vuejs/vue/issues/7209 https://github.com/vuejs/pinia/discussions/988 There are cases where you need some data fetched before other components are initialized (mount hook called), for example authentication checked or user data fetched. Currently need to use watches, which might be multiple, instead of a simple mounted hook in child components.

What does the proposed API look like?

Just the same as serverPrefetch, but on client.

mefcorvi commented 2 years ago

Can't this be achieved by using the async setup and Suspense? Or by using the navigation guards from vue-router?