vue-toastification icon indicating copy to clipboard operation
vue-toastification copied to clipboard

Nuxt 3 support

Open sahmadreza opened this issue 2 years ago • 8 comments

Support Nuxt 3

sahmadreza avatar May 10 '22 20:05 sahmadreza

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

gobboo avatar Jul 09 '22 21:07 gobboo

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

LynxTR avatar Aug 18 '22 01:08 LynxTR

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'
 ],

mykkode avatar Sep 08 '22 09:09 mykkode

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();
}

jiblett1000 avatar Feb 06 '23 06:02 jiblett1000

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?

akbarism avatar Feb 10 '23 07:02 akbarism

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.

kpetrillo avatar Apr 12 '23 20:04 kpetrillo

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

kouts avatar Apr 23 '23 14:04 kouts