Skip to content

Commit

Permalink
Merge pull request #103 from danielwaltz/fix-global-component
Browse files Browse the repository at this point in the history
fix: use nuxt add component util for toaster
  • Loading branch information
xiaoluoboding authored Nov 20, 2024
2 parents 5c7cc21 + 17adfb9 commit a302447
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
import {
defineNuxtModule,
addComponent,
addPlugin,
createResolver
} from '@nuxt/kit'

import type { NuxtModule } from '@nuxt/schema'

Expand All @@ -16,6 +21,12 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
setup(options: ModuleOptions, nuxt) {
const { resolve } = createResolver(import.meta.url)

addComponent({
name: 'Toaster',
export: 'Toaster',
filePath: 'vue-sonner'
})

addPlugin({
src: resolve('./runtime/plugin'),
mode: 'client'
Expand Down
8 changes: 2 additions & 6 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Toaster, toast } from 'vue-sonner'
import { toast } from 'vue-sonner'
import { defineNuxtPlugin } from 'nuxt/app'

import type { NuxtApp } from 'nuxt/app'

export default defineNuxtPlugin((nuxtApp: NuxtApp) => {
nuxtApp.vueApp.component('Toaster', Toaster)

export default defineNuxtPlugin(() => {
return {
provide: {
toast
Expand Down

0 comments on commit a302447

Please sign in to comment.