I am trying to access an element in Vue as I want to see when it's class changes (I'm using Bootstrap so I want to watch for when a class changes to shown). The problem is that as soon as I put a ref'd element into a v-for loop it always returns null. I have tried appending the ref's name with the index of the loop item, and then trying to log this to the console it just always returns 'null'.
As soon as I take the element out of the v-for loop it returns the element fine.
I can't seem to find a solution. Is this something that Vue just simply doesn't support? If not, is there a better way for me to watch the DOM to see if an element's class changes?
P.S. I'm using the composition API.
Template:
<template>
<div v-for="room in rooms" :key="room.id" class="">
<p class="test" :ref="'test'+room.id">Hello world</p>
</div>
</template
Script:
setup(){
const test1 = ref(null)
onMounted(() => {
console.log("test1: ", test1.value)
})
return { test1 }
}