Enickkey
Enickkey

Reputation: 59

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

Upvotes: 3

Views: 1960

Answers (1)

DengSihan
DengSihan

Reputation: 3007

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

Upvotes: 1

Related Questions