Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How use with Nuxt 3? #232

Open
MaxCpp opened this issue May 22, 2023 · 4 comments
Open

How use with Nuxt 3? #232

MaxCpp opened this issue May 22, 2023 · 4 comments

Comments

@MaxCpp
Copy link

MaxCpp commented May 22, 2023

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
Copy link

Facing same issue

@nick-nds
Copy link

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

@Sirkastik
Copy link

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
Copy link

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");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants