溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

詳解vue中在循環(huán)中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法

發(fā)布時間:2020-08-20 20:33:12 來源:腳本之家 閱讀:562 作者:錢不多啊 欄目:web開發(fā)

最近在項目中實現在循環(huán)出來的圖片中當鼠標移入隱藏當前圖片顯示另一張圖片的需求時碰到了一個小問題。就是當使用@mouseenter 和@mouseleave事件來實現這個需求時卻發(fā)現鼠標移入后圖片出現閃爍現象。

重點:事件寫到父元素上才行!??! 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中在循環(huán)中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法

到此這篇關于詳解vue中在循環(huán)中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法的文章就介紹到這了,更多相關vue @mouseenter @mouseleave事件閃爍內容請搜索億速云以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持億速云!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI