我有这个VueJS 2模板
var aThing = Vue.component('something',{
template :` <button @click="$emit('custom-event','hello there')">Click me</button>`});是否可以将实际按下的按钮作为参数传递给$emit?例如,在click事件中,它通常是传递的,但事件和可以在如下所示的函数中访问
function(event){
event.target; //I want this
}这是我的问题的一个jsfiddle
发布于 2017-12-19 03:53:58
Vue通过一个名为$event的变量使事件对象在模板中可用。这是documented here。
在这种情况下,您可以用这种方式发出事件的目标:
$emit('custom-event', 'hello-there', $event.target)https://stackoverflow.com/questions/47875017
复制相似问题