import { watch } from 'vue' ; import { useStore } from '@/store' ; export default ( ) => { const store = useStore ( ) ; function hideToast ( ) { store . isShowToast . value = false ; store . toastMessage . value = '' ; } function showToast ( message ) { if ( store . isShowToast . value ) { store . isShowToast . value = false ; setTimeout ( ( ) => { showToast ( message ) ; } , 500 ) ; return ; } store . toastMessage . value = message ; store . isShowToast . value = true ; } watch ( ( ) => store . isShowToast . value , val => { if ( val ) { store . toastQueue . push ( setTimeout ( ( ) => { hideToast ( ) ; } , 3000 ) ) ; } else { store . toastQueue . forEach ( clearTimeout ) ; store . toastQueue . length = 0 ; } } ) ; return { isShowToast : store . isShowToast , toastMessage : store . toastMessage , showToast , hideToast } ; } ;