Taha Khabouss
Taha Khabouss

Reputation: 70

I have a problem with finding the app instance in Nuxt 3

I'm new to nuxtjs, and I want to migrate my existing web application into Nuxt3 but I have an issue with finding the app instance, usually in Vue3 I use this approach to create an app instance

import App from "./App.vue";
const app = createApp(App);

and then use the app instance in other parts of the application, like:

import { app } from '../main';
const email = app.config.globalProperties.email;

how can I get the app instance in nuxt3 ?

I have tried different approaches such as this.$nuxt.app Vue.use() but non of them worked.

Upvotes: 0

Views: 2543

Answers (1)

Ennio Visconti
Ennio Visconti

Reputation: 126

It is not very easy to understand the specific context where you want to do this. However, you probably want to do:

// No imports are neeeded, nuxt takes care of base imports...
const app = useNuxtApp().vueApp
// or... using object detstructuring like it's modern js/ts
const { vueApp } = useNuxtApp()

which should work in most cases: https://nuxt.com/docs/api/composables/use-nuxt-app#methods.

However, please, be aware that for most use cases where you traditionally need to use it in a classic Vue 2 app, you should not use it in a Nuxt 3 app, as there are usually better ways to do the same thing.

Upvotes: 1

Related Questions