Search code examples
vue.jsnuxt.jsnuxt3.jsprimevue

how to integrate toast prive into nuxt3?


I'm using the primeVue library. I have not used nuxt before and this component worked for me. I registered it as a plugin in main.ts like this.

import ToastService from "primevue/toastservice"
app.use(ToastService)

How can I get it to work in nuxt? It immediately throws out the error No PrimeVue Toast provided! as soon as I try to call useToast


Solution

  • you have to define a nuxt plugin before using "primevue/toastservice"

    add a plugin plugins/primevue-toastservice.ts first

    import ToastService from 'primevue/toastservice'
    
    export default defineNuxtPlugin((nuxtApp) => {
        nuxtApp.vueApp.use(ToastService);
    });
    

    now you can use it

    read the nuxt3 plugins document for more details