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

Nuxt 3 support #333

Open
sahmadreza opened this issue May 10, 2022 · 8 comments
Open

Nuxt 3 support #333

sahmadreza opened this issue May 10, 2022 · 8 comments
Labels
Type: Enhancement New feature or request

Comments

@sahmadreza
Copy link

Support Nuxt 3

@sahmadreza sahmadreza added the Type: Enhancement New feature or request label May 10, 2022
@gobboo
Copy link

gobboo commented Jul 9, 2022

Currently working on Nuxt 3 for me if I make a new plugin

import Toast from "vue-toastification";
import "vue-toastification/dist/index.css";

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

@LynxTR
Copy link

LynxTR commented Aug 18, 2022

For noticing further nuxt 3 users like me, you need to set transpile for this package before using it at production. Otherwise toast used pages will throw 500 error as dist.useToast is not a function when you refresh the browser or at initial site openning.

// nuxt.config.ts
export default defineNuxtConfig({
   build : {
      transpile: ['vue-toastification']
   }
})

For now, this is the only solution i able to find out. Tested nuxt version is rc.8

@mykkode
Copy link

mykkode commented Sep 8, 2022

Another way to use vue-toastification with vue3 and nuxt3:

Create vue-toastification.client.js in /plugins with the following content:

import Toast from 'vue-toastification/dist/index.mjs'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(Toast, {})
})

Also you have to import useToast this way:
import { useToast } from 'vue-toastification/dist/index.mjs'

And to import the toast style, add in nuxt.config.js:

css: [
    ...
    'vue-toastification/dist/index.css'
 ],

cbasje added a commit to cbasje/christmas-gifts that referenced this issue Oct 17, 2022
@jiblett1000
Copy link

jiblett1000 commented Feb 6, 2023

Additionally, to avoid importing useToast everywhere, you can just add a composable in the composables directory like so....

import { useToast } from "vue-toastification";

export default function () {
  return useToast();
}

@akbarism
Copy link

Another way to use vue-toastification with vue3 and nuxt3:

Create vue-toastification.client.js in /plugins with the following content:

import Toast from 'vue-toastification/dist/index.mjs'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(Toast, {})
})

Also you have to import useToast this way: import { useToast } from 'vue-toastification/dist/index.mjs'

And to import the toast style, add in nuxt.config.js:

css: [
    ...
    'vue-toastification/dist/index.css'
 ],

is this work in production?

@kpetrillo
Copy link

Another way to use vue-toastification with vue3 and nuxt3:
Create vue-toastification.client.js in /plugins with the following content:

import Toast from 'vue-toastification/dist/index.mjs'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(Toast, {})
})

Also you have to import useToast this way: import { useToast } from 'vue-toastification/dist/index.mjs'
And to import the toast style, add in nuxt.config.js:

css: [
    ...
    'vue-toastification/dist/index.css'
 ],

is this work in production?

It works for me in production; I'm using Digital Ocean / Cleavr.

@kouts
Copy link

kouts commented Apr 23, 2023

Here's what worked for me using nuxt 3.4.2

Added

build: { transpile: ['vue-toastification'] },
css: ['vue-toastification/dist/index.css']`

to nuxt.config.ts

Added plugins/vue-toastificaton.client.ts

import Toast, { PluginOptions } from 'vue-toastification'

const options: PluginOptions = {
  // We can set our default options here
}

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(Toast, options)
})

Added composables/useToast.ts

import { useToast } from 'vue-toastification'

export default function () {
  return useToast()
}

I've tested production build with
nuxt build and nuxt preview

@achraf-prestigia
Copy link

this solution fixed my issue:
nuxt/nuxt#14790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants