Files
ezbookkeeping/src/components/desktop/SnackBar.vue
T

44 lines
1015 B
Vue

<template>
<v-snackbar v-model="showState">
{{ messageContent }}
<template #actions>
<v-btn color="primary" variant="text" @click="showState = false">{{ $t('Close') }}</v-btn>
</template>
</v-snackbar>
</template>
<script setup lang="ts">
import { type Ref, ref, watch } from 'vue';
import { useI18n } from '@/lib/i18n.js';
const emit = defineEmits<{
(e: 'update:show', value: boolean): void
}>();
const { tt, te } = useI18n();
const showState: Ref<boolean> = ref(false);
const messageContent: Ref<string> = ref('');
function showMessage(message: string, options: Record<string, unknown>): void {
showState.value = true;
messageContent.value = tt(message, options);
}
function showError(error: string | { message: string }): void {
showState.value = true;
messageContent.value = te(error.message || error);
}
watch(showState, (newValue) => {
emit('update:show', newValue);
});
defineExpose({
showMessage,
showError
});
</script>