Open MaxCpp opened 1 year ago
Facing same issue
Same issue with Vue 3. I think it will not work with Vue 3.
import VueToasted from "vue-toasted";
export default defineNuxtPlugin((nuxtApp) => {
// necessary to make it work with Vue 3 and Nuxt 3
const prevPrototype = nuxtApp.vueApp.prototype;
nuxtApp.vueApp.prototype = {};
nuxtApp.vueApp.use(VueToasted, {
/* options */
});
Object.assign(
nuxtApp.vueApp.config.globalProperties,
nuxtApp.vueApp.prototype
);
nuxtApp.vueApp.prototype = prevPrototype;
});
import VueToasted from "vue-toasted"; export default defineNuxtPlugin((nuxtApp) => { // necessary to make it work with Vue 3 and Nuxt 3 const prevPrototype = nuxtApp.vueApp.prototype; nuxtApp.vueApp.prototype = {}; nuxtApp.vueApp.use(VueToasted, { /* options */ }); Object.assign( nuxtApp.vueApp.config.globalProperties, nuxtApp.vueApp.prototype ); nuxtApp.vueApp.prototype = prevPrototype; });
Thanks, that finally worked. For those who don't get what's going on, that's a source code of a plugin. To call a toast from a component or a page:
const nuxtApp = useNuxtApp();
...
nuxtApp.vueApp.toasted.success("OK");
I try add vue-toasted in Nuxt 3:
But I have error in console:
How it's right to do? I know about @nuxtjs/toast but it doesn't work with Nuxt 3.