[Vuejs]-Where and how best to call the first initial server-side external API query in Nuxt 3?

0👍

You can make a plugin and have it hooked into an event and then setup everything. More on which hooks are available

// plugins/setup.ts
export default defineNuxtPlugin((nuxtApp) => {

    nuxtApp.hook('app:created', () => {
        Log.info('App created');
    });
    nuxtApp.hook('app:mounted', () => {
        Log.info('App mounted');
    });
});

An alternative is that you write everything in the layouts/default.vue to set everything up in an onMounted hook, but I find this a bit hacky as you ideally want to separate UI from business logic

Leave a comment