use in nuxt #50
ErfanBahramali
started this conversation in
General
Replies: 3 comments
-
I had the same problem with nuxt3, using vite + vue 3 works fine. |
Beta Was this translation helpful? Give feedback.
0 replies
-
it's work for me in nuxt3 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here is the wrapper component ( <script setup lang="ts">
import { NotificationGroup, Notification } from "notiwind"
import ToastNotification from "@/components/ToastNotification.vue"
</script>
<template>
<!-- global notification region, rendered permanently in document -->
<NotificationGroup>
<div
aria-live="assertive"
class="pointer-events-none fixed z-50 inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6"
>
<div class="flex w-full flex-col items-center space-y-4 sm:items-end">
<!-- notification data is fed through the slot below -->
<Notification
v-slot="{ notifications, close }"
enter="transform ease-out duration-300 transition"
enter-from="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
enter-to="translate-y-0 opacity-100 sm:translate-x-0"
leave="transition ease-in duration-100"
leave-from="opacity-100"
leave-to="opacity-0"
>
<ToastNotification
v-for="notification in notifications"
:key="notification.id"
:notification="notification"
:close="close"
/>
</Notification>
</div>
</div>
</NotificationGroup>
</template>
This component is included in my primary layout like this: <script setup>
import SiteHeader from "@/components/SiteHeader.vue"
import ToastNotifications from "@/components/ToastNotifications.vue"
</script>
<template>
<Html class="h-full bg-gray-50" />
<Body class="h-full" />
<div class="min-h-full">
<ToastNotifications />
<SiteHeader />
<main>
<slot />
</main>
</div>
</template> My nuxt plugin looks like this: import { defineNuxtPlugin } from "#app"
import Notifications, { notify } from "notiwind"
type NotificationOptions = {
group?: string
title: string
text: string
type?: "info" | "success" | "warn" | "error"
}
// core method, use with $toast("foo")
function notifyFlexible(
info: string | NotificationOptions,
displayFor?: number,
type?: "info" | "success" | "warn" | "error"
) {
if (typeof info === "string") {
notify({ title: info, type }, displayFor)
} else {
notify(info, displayFor)
}
}
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(Notifications)
return {
provide: {
toast: notifyFlexible,
},
}
}) The const { $toast } = useNuxtApp()
$toast("hello world") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi
I want to use
notiwind
in nuxtjsFirst, I installed it and registered it as a plugin
Second, I added notification components as
Notification.vue
file incomponents
Third, I used it in a page (example
notiwind.vue
).But I encountered the errors that you can see below
Sources:
install:
Notification.client.js:
Notification.vue:
notiwind.vue:
Errrors (In Terminal):
Errors (In Inspect Console):
Apparently, it does't recognize the
NotificationGroup
at allWhat's the problem and the solution ?
Beta Was this translation helpful? Give feedback.
All reactions