shakee93 / vue-toasted

🖖 Responsive Touch Compatible Toast plugin for VueJS 2+
https://shakee93.github.io/vue-toasted/
MIT License
2.21k stars 194 forks source link

How use with Nuxt 3? #232

Open MaxCpp opened 1 year ago

MaxCpp commented 1 year ago

I try add vue-toasted in Nuxt 3:

import { defineNuxtPlugin } from '#app';
import Toasted from 'vue-toasted';

export default defineNuxtPlugin((nuxtApp) => {
    nuxtApp.vueApp.use(Toasted);
})

But I have error in console: image

How it's right to do? I know about @nuxtjs/toast but it doesn't work with Nuxt 3.

viveksharma619 commented 1 year ago

Facing same issue

nick-nds commented 11 months ago

Same issue with Vue 3. I think it will not work with Vue 3.

victor-rioba commented 4 months ago
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;
});
AlexGnatko commented 4 months ago
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");