詳解vue中在循環(huán)中使用@mouseenter 和 @mouseleave事件閃爍問(wèn)題解決方法
最近在項(xiàng)目中實(shí)現(xiàn)在循環(huán)出來(lái)的圖片中當(dāng)鼠標(biāo)移入隱藏當(dāng)前圖片顯示另一張圖片的需求時(shí)碰到了一個(gè)小問(wèn)題。就是當(dāng)使用@mouseenter 和@mouseleave事件來(lái)實(shí)現(xiàn)這個(gè)需求時(shí)卻發(fā)現(xiàn)鼠標(biāo)移入后圖片出現(xiàn)閃爍現(xiàn)象。
重點(diǎn):事件寫(xiě)到父元素上才行!!! 0.0
下面寫(xiě)下我的實(shí)現(xiàn)方法和實(shí)現(xiàn)效果
樣式代碼:
<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(’鼠標(biāo)移入’); this.show = false; this.n = index;},leaveFun(index){ console.log(’鼠標(biāo)離開(kāi)’); this.show = true; this.n = index;},} }
最終實(shí)現(xiàn)效果如圖 當(dāng)鼠標(biāo)移入圖片時(shí)當(dāng)前圖片顯示查看詳情:

到此這篇關(guān)于詳解vue中在循環(huán)中使用@mouseenter 和 @mouseleave事件閃爍問(wèn)題解決方法的文章就介紹到這了,更多相關(guān)vue @mouseenter @mouseleave事件閃爍內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁(yè)效果(實(shí)例代碼)2. 詳解Android studio 動(dòng)態(tài)fragment的用法3. 圖文詳解vue中proto文件的函數(shù)調(diào)用4. 解決Android studio xml界面無(wú)法預(yù)覽問(wèn)題5. php模擬實(shí)現(xiàn)斗地主發(fā)牌6. 什么是python的自省7. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)8. Vuex localStorage的具體使用9. vue 使用localstorage實(shí)現(xiàn)面包屑的操作10. .Net Core使用Coravel實(shí)現(xiàn)任務(wù)調(diào)度的完整步驟

網(wǎng)公網(wǎng)安備