Is there a way to fetch data from an API and populate my store (such as user info) before the entire page and components load? I have been struggling to find a solution.
I recently came across the beforeRouteEnter
method that can be used with the options API, but what about using the composition API (especially with <script setup>
)?
I attempted the following:
const router = useRouter()
router.beforeResolve(() => {
// Fetch API and populate store
})
And also tried this:
router.beforeEach(() => {
// Fetch API and populate store
})
Unfortunately, neither of these methods achieved the desired outcome.