詳解vue中在迴圈中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法
阿新 • • 發佈:2020-04-08
最近在專案中實現在迴圈出來的圖片中當滑鼠移入隱藏當前圖片顯示另一張圖片的需求時碰到了一個小問題。就是當使用@mouseenter 和@mouseleave事件來實現這個需求時卻發現滑鼠移入後圖片出現閃爍現象。
重點:事件寫到父元素上才行!!! 0.0
下面寫下我的實現方法和實現效果
樣式程式碼:
<div class="imgs" v-for="(item,index) in exampleUrl" :key = index @mouseenter ="enterFun(index)" @mouseleave ="leaveFun(index)" > <img :src = item.url v-show="show || n != index" > <div v-show="!show && n == index" >檢視詳情</div> </div>
其他程式碼:
export default { data () { return { n: 0,show:true,} },methods: { enterFun(index){ console.log('滑鼠移入'); this.show = false; this.n = index; },leaveFun(index){ console.log('滑鼠離開'); this.show = true; this.n = index; },} }
最終實現效果如圖 當滑鼠移入圖片時當前圖片顯示檢視詳情:
到此這篇關於詳解vue中在迴圈中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法的文章就介紹到這了,更多相關vue @mouseenter @mouseleave事件閃爍內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!