我希望能够在鼠标悬停时更改图像的src。以下是我的代码:
<li v-for="(item, key) in items" @mouseover="changeImg">
<img :src="item.img.grey">
<p>{{key}}</p>
</li>
<script>
app = new Vue({
el: '#app',
data: {
items: {
first:{
img:{
grey:'assets/img/first-grey.png',
green:'assets/img/first-green.png'
}
},
second:{
img:{
grey:'assets/img/second-grey.png',
green:'assets/img/second-green.png'
}
},
},
},
methods: {
changeImg(key) {
//selected li's image should be green
}
}
})
</script>
在悬停在li元素上后,我希望悬停的图像变为绿色。