From 7efa425c85ffe94420ad62c281b5766c279a1fa2 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Wed, 18 Dec 2024 08:42:00 +0800 Subject: [PATCH] use nuxt plugin instead of function --- app.vue | 3 ++- components/alert/Notification.vue | 6 +++--- composables/emitter.ts | 10 ---------- error.vue | 10 +++++++++- pages/article.vue | 3 ++- pages/error/maintenance.vue | 4 +++- pages/index.vue | 3 ++- plugins/mitt.ts | 19 +++++++++++++++++++ 8 files changed, 40 insertions(+), 18 deletions(-) delete mode 100644 composables/emitter.ts create mode 100644 plugins/mitt.ts diff --git a/app.vue b/app.vue index 882da3d..87786e7 100644 --- a/app.vue +++ b/app.vue @@ -1,7 +1,8 @@ diff --git a/composables/emitter.ts b/composables/emitter.ts deleted file mode 100644 index c472f5a..0000000 --- a/composables/emitter.ts +++ /dev/null @@ -1,10 +0,0 @@ -import mitt from 'mitt' - -type Events = { - openPost: IPost - startLoading: boolean - eventBus: INotification -} - -const emitter = mitt() -export default emitter \ No newline at end of file diff --git a/error.vue b/error.vue index 26c1df4..0009506 100644 --- a/error.vue +++ b/error.vue @@ -1,10 +1,13 @@ diff --git a/pages/article.vue b/pages/article.vue index 61c76f4..621f28e 100644 --- a/pages/article.vue +++ b/pages/article.vue @@ -1,7 +1,8 @@ diff --git a/pages/error/maintenance.vue b/pages/error/maintenance.vue index bb01b33..068d3ba 100644 --- a/pages/error/maintenance.vue +++ b/pages/error/maintenance.vue @@ -1,6 +1,8 @@ diff --git a/pages/index.vue b/pages/index.vue index 0706bf4..782e075 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,6 +1,7 @@ diff --git a/plugins/mitt.ts b/plugins/mitt.ts new file mode 100644 index 0000000..d6ce654 --- /dev/null +++ b/plugins/mitt.ts @@ -0,0 +1,19 @@ +import mitt from 'mitt' + +type Events = { + openPost: IPost + startLoading: boolean + eventBus: INotification +} + + + +export default defineNuxtPlugin(() => { + const emitter = mitt() + + return { + provide: { + mitt: emitter + } + } +}) \ No newline at end of file