vue实现悬停一段时间改变style
作者:互联网
<div id="demo"> <div @mouseover="mouseOver" @mouseleave="mouseLeave" :style="active">悬停两秒后改变颜色</div> </div>
<script> var demo=new Vue({ el:'#demo', data:{ active:'' }, methods:{ mouseOver:function(){ timer=setTimeout(()=>{ this.active='background-color:#aaaaff'; },2000); }, mouseLeave:function() { clearTimeout(timer); this.active=''; } } }); </script>
标签:function,style,vue,demo,timer,active,悬停,两秒 来源: https://www.cnblogs.com/watm/p/15469133.html