I solved it, not the most elegant solution but the flash message displays. The Layout watches for changes in the requests of the flash message object - this is the code in the Layout.vue:
import {useFlashStore} from "@/stores/FlashStore.js";
// get the flash object from the flash store
let flashWatch = useFlashStore();
// watch the flash object for changes
watch(
() => props.flash,
(flash) => {
if (props.flash.error) {
console.log("flash object is passed to layout component");
flashWatch.error = props.flash.error;
flashWatch.show = true;
} else if (props.flash.success) {
console.log("flash object is passed to layout component");
flashWatch.success = props.flash.success;
flashWatch.show = true;
} else if (props.flash.warning) {
console.log("flash object is passed to layout component");
flashWatch.warning = props.flash.warning;
flashWatch.show = true;
} else if (props.flash.info) {
console.log("flash object is passed to layout component");
flashWatch.info = props.flash.info;
flashWatch.show = true;
}
}
);
let props = defineProps({
flash: Object,
});
Then then in the flash message, I read the store & check watch to see if the value of flash.show in the store is true, then render the message & hide it after 3 seconds. This is the code:
<template>
<Teleport v-if="loaded" to="body">
<Transition
enter-from-class="ease-in-out opacity-0 scale-75 translate-y-12"
enter-to-class="ease-in-out opacity-100 scale-100"
enter-active-class="transition ease-in-out duration-300 translate-y-0"
leave-from-class="ease-in-out opacity-100 scale-100 translate-y-0"
leave-to-class="ease-in-out opacity-0 scale-75 translate-y-12"
leave-active-class="transition ease-in-out duration-300"
>
<div v-if="flash.show">
<div v-if="flash.success"
class="fixed bottom-4 right-4 text-white py-4 px-4 rounded-xl text-md hover:opacity-75 z-50 bg-[conic-gradient(at_top_right,_var(--tw-gradient-stops))] from-indigo-900 via-slate-900 to-teal-500">
{{ flash.success }}
</div>
<div v-else-if="flash.error"
class="fixed bottom-4 right-4 text-white py-4 px-4 rounded-xl text-md hover:opacity-75 z-50 bg-red-500">
{{ flash.error }}
</div>
<div v-else-if="flash.warning"
class="fixed bottom-4 right-4 text-white py-4 px-4 rounded-xl text-md hover:opacity-75 z-50 bg-yellow-500">
{{ flash.warning }}
</div>
<div v-else-if="flash.info"
class="fixed bottom-4 right-4 text-white py-4 px-4 rounded-xl text-md hover:opacity-75 z-50 bg-[radial-gradient(ellipse_at_bottom_right,_var(--tw-gradient-stops))] from-sky-400 to-indigo-900">
{{ flash.info }}
</div>
</div>
</Transition>
</Teleport>
</template>
<script setup>
import {onMounted, ref, watch} from "vue";
import {useFlashStore} from "@/Stores/FlashStore.js";
// create a ref to track if the component has been loaded
let flash = useFlashStore();
// create a ref to track if the component has been loaded
let loaded = ref(false);
// when the value in the store is set to true and the component is rendered, set loaded to true
onMounted(() => {
// teleport the component to the body
loaded.value = true;
console.log("loading & teleporting component");
});
// watch the value of show and if it is true, set it to false after 3 seconds
watch(
() => loaded.value,
(track) => {
if (track) {
//hide the message after 3 seconds
setTimeout(() => {
// clear the value of the flash message
flash.error = "";
flash.success = "";
flash.warning = "";
flash.info = "";
// hide the message
flash.show = false;
// unmount the component
console.log("hiding message");
}, 3000);
}
}
);
</script>
However, now my transitions will not work. I'll make a new post to see if anyone can help.