詳解vue中在循環中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法
最近在項目中實現在循環出來的圖片中當鼠標移入隱藏當前圖片顯示另一張圖片的需求時碰到了一個小問題。就是當使用@mouseenter 和@mouseleave事件來實現這個需求時卻發現鼠標移入后圖片出現閃爍現象。
重點:事件寫到父元素上才行!!! 0.0
下面寫下我的實現方法和實現效果
樣式代碼:
<div 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事件閃爍內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. 解決Android Studio 格式化 Format代碼快捷鍵問題2. 完美解決vue 中多個echarts圖表自適應的問題3. 在Chrome DevTools中調試JavaScript的實現4. Springboot 全局日期格式化處理的實現5. SpringBoot+TestNG單元測試的實現6. Java使用Tesseract-Ocr識別數字7. vue實現web在線聊天功能8. JAMon(Java Application Monitor)備忘記9. IntelliJ IDEA設置自動提示功能快捷鍵的方法10. Python使用urlretrieve實現直接遠程下載圖片的示例代碼
