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

Posted lovebear123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue 点击,鼠标移动上去显示隐藏相关的知识,希望对你有一定的参考价值。

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 点击,鼠标移动上去显示隐藏的主要内容,如果未能解决你的问题,请参考以下文章

Winform 最小化 最大化 关闭 点击任务栏隐藏显示 点击鼠标左键移动窗体

selenium 怎么查找定位鼠标移上去显示,移开鼠标就消失的内容

selenium 怎么查找定位鼠标移上去显示,移开鼠标就消失的内容

Vue(26)el-tree树形控件实现鼠标hover显示与隐藏

jQuery 通过鼠标摇拽改变div的大小

Excel中 鼠标移动到那里会变颜色,不是鼠标点击一下才变的那种?