在Vue.js中,我可以将图像绑定到img元素:
<img v-bind:src="myimage" />
如何定义鼠标在此图像上移动时显示的其他图像?
答案 0 :(得分:5)
更改myImage
监听器中mouseover
的值:
new Vue({
el: '#app',
data() {
return {
myImage: "https://s-media-cache-ak0.pinimg.com/originals/bd/5d/84/bd5d845c980508d41b0329dc21d08d2b.jpg",
otherImage: "https://cdn.pixabay.com/photo/2014/03/29/09/17/cat-300572_960_720.jpg"
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script>
<div id="app">
<img :src="myImage" @mouseover="myImage = otherImage"/>
</div>