热搜:fiddler git ip ios 代理
历史搜索

Vue项目实现鼠标移入移出更改图片代码

游客2024-11-26 07:30:02

HTML 代码:

<div>
  <div>
    <img  :src="picture" />
  </div>
  <div
    
    @mouseover="everMouseover()"
    @mouseleave="elevMouseleave()"
  ></div>
</div>

CSS 代码:

.main {
  height: 300px;
  width: 100px;
}
 
.imgs {
  height: 100%;
}
.a {
  background-color: brown;
  width: 200px;
  height: 100px;
}

JS 代码:

export default {
  data() {
    return {
      imgObj: {
        immigrate: require("./img/tu1.jpeg"),
        shift_out: require("./img/tu2.jpeg"),
      },
      picture: require("./img/tu1.jpeg"),
    };
  },
  model: {
    //鼠标移入触发
    everMouseover: function () {
      this.picture = this.imgObj.immigrate;
    },
    //鼠标移出触发
    elevMouseleave: function () {
      this.picture = this.imgObj.shift_ouf;
    },
  },
};
标签:vue.js