I'm facing an issue where I want a div to only appear once a specific variable changes from false to true. I have tried changing the value of the variable once the component is mounted, but the v-if directive does not seem to work as expected in displaying the div.
<script setup>
import { onMounted } from 'vue'
let onceMounted = false
onMounted(() => {
onceMounted = true
console.log(onceMounted)
});
<div>
Hello
<div v-if="onceMounted === true">
World
</div>
</div>
Although the console log shows that the variable changes correctly, the v-if
directive does not update the div. I have even tried using v-show
after researching similar issues like this one. Is there something essential that I might be overlooking?