I have this VueJS 2 template
var aThing = Vue.component('something',{
template :` <button @click="$emit('custom-event','hello there')">Click me</button>`});
Is it possible to pass the button that was actually pushed as an argument to $emit
? For example in the click
event it is usually passed but the event and can be accesed in a function like this
function(event){
event.target; //I want this
}
Here is a jsfiddle of my issue
https://jsfiddle.net/wntzv4sk/2/
Vue makes the event object available in the template via a variable called $event
. This is documented here.
That being the case, you could emit the target of the event in this manner:
$emit('custom-event', 'hello-there', $event.target)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With