Skip to content

用v-on绑定事件是否有方法获取到触发的this对象 #1999

@ikarosu

Description

@ikarosu

首先我知道可以用e.target获取到点击到的元素
但有这么一种情况:<a @click="foo" data-id="2015"><i>修饰文本</i>主要文本内容</a>
在这种情况下我点击到了<i>标签同样会触发事件,但是我的e.target获取到的就是<i>
有没有那么一种方法,可以让我像原生绑定的时候一样,可以直接用this.dataset.id获取到我想要的那个

我目前的解决思路有两种:
1.给<i>标签添加pointer-events:none样式
2.给<i>标签同样绑上data-id属性

希望得到更好的解决方案

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions