首页 > 移动平台 > 详细

vue 点击,鼠标移动上去显示隐藏

时间:2019-12-19 18:09:45      阅读:593      评论:0      收藏:0      [点我收藏+]

1,鼠标点击显示隐藏,样式可以自己调,我就写个dome。


<div class="min"> <button @click="change">点击我</button> <div v-show="show"> 显示隐藏的内容 </div> </div>

<script>
export default {
  name: "testresult",
  data() {
    return {
      show: false
    };
  },
  methods: {
    change() {
      this.show = !this.show;
    }
  }
};
</script>


 

鼠标移动上去事件:

html:

技术分享图片
  <div class="min">
      <button
        class="cancelbtn"
        @mouseover="mouseover(n)"
        @mouseleave="mouseleave"
        v-show="isshow & (n == id)"
      >
        取消</button
      ><br />
      <button
        class="followbtn"
        @mouseover="mouseover(n)"
        @mouseleave="mouseleave"
      >
        关注
      </button>
    </div>
View Code

 

js

技术分享图片
<script>
export default {
  name: "testresult",
  data() {
    return {
      isshow: false,
      id: 0
    };
  },
  methods: {
    // 移入
    mouseover(id) {
      this.id = id;
      clearTimeout(this.timer);
      this.isshow = true;
    },
    // 移出
    mouseleave() {
      this.timer = setTimeout(() => {
        this.isshow = false;
      }, 100);
    }
  }
};
</script>
View Code

 

css:

.followbtn {
  width: 50px;
  height: 30px;
  text-align: center;
  background-color: coral;
  color: #ffffff;
  border: 0;
}
.cancelbtn {
  width: 50px;
  height: 30px;
  text-align: center;
  background-color: brown;
  color: #ffffff;
  border: 0;
}

效果图:

技术分享图片   技术分享图片

vue 点击,鼠标移动上去显示隐藏

原文:https://www.cnblogs.com/lovebear123/p/12069245.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!