Maronato / vue-toastification

Vue notifications made easy!
https://vue-toastification.maronato.dev
MIT License
3.03k stars 139 forks source link

Nuxt 3 support #333

Open sahmadreza opened 2 years ago

sahmadreza commented 2 years ago

Support Nuxt 3

gobboo commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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'
 ],
jiblett1000 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 2 months ago

this solution fixed my issue: https://github.com/nuxt/nuxt/issues/14790