How can I make an object property reactive?
When I run the code below, the imported visible doesn't change to true.
Component that imports the object:
<template>
<div class="context">
<span v-if="visible"> test </span>
</div>
</template>
<script>
import { ContextManager } from "./utils.js";
import { ref } from "vue";
export default {
name: "context",
setup() {
const visible = ref(ContextManager.visible);
return { visible };
}
};
</script>
Other component that adds data to the object:
const openContext = (e) => {
e.preventDefault();
ContextManager.add({
el: e.target,
items: contextItems
},e );
};
ContextManager object:
import { reactive } from "vue";
export const ContextManager = reactive({
context: null,
visible: false,
add(context, e) {
this.visible = true;
}
});