简体   繁体   English

如何在Vuejs中鼠标悬停时隐藏div元素?

[英]How to hide div element on hover of mouse in Vuejs?

 new Vue({ el: '#mouse', data: { showByIndex: null }, methods: { } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="mouse"> <div class="parent" v-for="i in 1" @mouseover="showByIndex = i" @mouseout="showByIndex = null"> <div class="child-one"> Some dummy text </div> <div class="child-two" v-show="showByIndex === i"> Show me only on hover on "div.parent" element </div> </div> </div>

Working example:- https://codepen.io/dhanunjayt/pen/XWgyqXW工作示例:- https://codepen.io/dhanunjayt/pen/XWgyqXW

With the above code i am able to show the text, when hover of the div element.使用上面的代码,我可以在 div 元素悬停时显示文本。 But small issue is when hover first element should not reflect.但小问题是悬停第一个元素不应该反映。

Like following snipppet?喜欢以下片段?

 new Vue({ el: '#mouse', data: { showByIndex: null }, methods: { } })
 .parent { padding: 2em; background: violet; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="mouse"> <div class="parent" v-for="i in 1" @mouseover="showByIndex = i" @mouseout="showByIndex = null"> <div class="child-one" v-show="showByIndex === null"> Some dummy text </div> <div class="child-two" v-show="showByIndex === i"> Show me only on hover on "div.parent" element </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM