vue中在循環中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法


vue移入移出事件,有可能新版本已經移除,做個記錄

ue中在循環中使用@mouseenter 和 @mouseleave事件閃爍問題解決方法

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

<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;
        },
    }       
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM