diff --git a/src/App.vue b/src/App.vue index 20d70e5..04bd0bd 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,6 +2,7 @@ @@ -10,6 +11,7 @@ import { computed } from 'vue'; import { useRoute } from 'vue-router'; import NormalLayout from './layouts/NormalLayout.vue'; import NoLayout from './layouts/NoLayout.vue'; +import ToastModal from '@c/modal/ToastModal.vue'; const route = useRoute(); diff --git a/src/components/modal/ToastModal.vue b/src/components/modal/ToastModal.vue new file mode 100644 index 0000000..b63c13f --- /dev/null +++ b/src/components/modal/ToastModal.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/src/main.js b/src/main.js index 14f4f3b..12ed27d 100644 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,7 @@ import piniaPersist from 'pinia-plugin-persist' import App from './App.vue' import router from '@/router' import dayjs from '@p/dayjs' +import ToastModal from '@c/modal/ToastModal.vue'; const pinia = createPinia() pinia.use(piniaPersist) @@ -12,9 +13,9 @@ const app = createApp(App) app.use(router) .use(pinia) .use(dayjs) + .component('ToastModal',ToastModal) .mount('#app') - if (import.meta.env.MODE === "prod") { const console = window.console || {}; console.log = function no_console() { }; // console log 막기 diff --git a/src/stores/toastStore.js b/src/stores/toastStore.js new file mode 100644 index 0000000..8822951 --- /dev/null +++ b/src/stores/toastStore.js @@ -0,0 +1,28 @@ +import { defineStore } from 'pinia'; + +export const useToastStore = defineStore('toastStore', { + state: () => ({ + toastModal: false, + toastMsg: '', + time: 2000, + toastType: 'success', // 'success' 또는 'error' + }), + actions: { + onToast(msg = '', time = 2000, type = 'success') { + this.toastModal = true; + this.toastMsg = msg; + this.time = time; + this.toastType = type; + + // 시간이 지난 후 토스트 숨기기 + setTimeout(() => { + this.offToast(); + }, this.time); + }, + offToast() { + this.toastModal = false; + this.toastMsg = ''; + this.toastType = 'success'; // 기본 상태로 초기화 + }, + }, +});