码迷,mamicode.com
首页 > 其他好文 > 详细

Vue——获取当前元素方法 $event

时间:2020-01-09 13:35:52      阅读:1208      评论:0      收藏:0      [点我收藏+]

标签:col   out   添加   背景色   code   color   button   htm   鼠标   

首先 vue的点击事件 是用 @click = “clickfun()” 属性 在html中绑定的,

在点击的函数中 添加$event 参数就可以了

<button @click = “clickfun($event)”>点击</button>

methods: {

    clickfun(e) {

        // e.target 是你当前点击的元素

        // e.currentTarget 是你绑定事件的元素

    }

},

 

修改样式

obj就是传入的$event

// 鼠标放上 修改当前tr标签的背景色

changeOver:function (obj) {

    obj.currentTarget.style.background="rgb(244, 250, 251)";

},

// 鼠标离开 changeOut:function (obj) { obj.currentTarget.style.background="white"; }

Vue——获取当前元素方法 $event

标签:col   out   添加   背景色   code   color   button   htm   鼠标   

原文地址:https://www.cnblogs.com/coder2020/p/12170681.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!