I am new to Vue and have a component A) Notification bar which has a Reactive object containing state, message. Then I want to show a div in another component based on the status of Reactive object in component A. Also I want to be able to change the Reactive object in component A from a method in component B. How do you achieve this?
Component A:
<template>
<div v-html="$notificationStore.message" v-if="$notificationStore.notify"></div>
</template>
<script setup>
import { reactive } from "vue";
const $notificationStore = reactive({
notify: false,
type: "",
message: ""
});
</script>
Component B:
<template>
<div v-if="!$notificationStore.notify"></div> <!-- Should read "notify" from Component A"-->
<button type="button" @click="ShowNotification('Message to show')"/>
</template>
<script setup>
import { reactive } from "vue";
function ShowNotification(message){
this.$notificationStore.notify = true;
this.$notificationStore.Message = message;
};
</script>
Thank you very much!