I have an array of products, I want to change the element src only on the one I'm hovering on. If there is a way of doing it in Vuejs I would like to know. My code so far
<div class="swiper-slide" v-for="(prodotto,index) in prodotti" :key="prodotto.title"> <img @mouseover="swapImage(index)" @mouseleave="swapImageLeave" class="swiper-lazy ima-prodotto" :key="index" :src=" hoverProdotti === 1 ? prodotto.images[0] : prodotto.images[1]" v- bind:alt="prodotto.title"> </div> const app = new Vue({ el: "#root", data: { hoverProdotti:0, }, methods: { swapImage: function(index) { console.log(index) this.hoverProdotti = 1 }, swapImageLeave: function() { this.hoverProdotti = 0 },
hoverProdotti[], i.e declared as an array, update it usingthis.hoverProdotti[index]and use it like:src = "hoverProdotti[index] === 1 .... etc"