I need assistance with creating a dynamic array of divs that will apply a class to both the div itself and a child element when hovered over. The array is generated by a computed function, as shown in the following code snippet:
<article
v-for="(article, index) in filteredArticles"
:key="article.id"
ref="articleRefs"
:ref-key="index"
@mouseenter="handleClass(index, 'add')"
@mouseleave="handleClass(index, 'remove')"
>
<!-- Content -->
</article
const articleRefs = ref<HTMLDivElement[]>([])
const articleList = ref([] as Article[])
const filteredArticles = computed(() => {
return activeTag.value !== ''
? articleList.value.filter((a) => a.tags.some((t) => t.Tag_id.title === activeTag.value))
: articleList.value
})
watch(
filteredArticles.value,
() => articleRefs.value = []
)
const handleClass = (index: number, action: 'add'|'remove') => {
const hoveredArticle = articleRefs.value[index]
hoveredArticle.classList[action]('animate')
hoveredArticle.querySelector('h2')?.classList[action]('glitch')
}
Initially, everything works fine. However, if an article that was previously filtered out is displayed again, hovering over it does not trigger the desired effect.
I would appreciate any insights on what might be causing this issue. Thank you!