2

I am following vue.js tutorial - method event handlers

    <button v-on:click='handler'>handle this</button>
    .
    .
    .
    methods: {
                handler: function (event) {                
                   console.log(JSON.stringify(event));
              }}

However when I try to display the event all i get is {"isTrusted":true}

When I tried console.log(event.target.tagName) I get an empty string.

I think I am supposed to get Button.

3
  • try <button type="button" v-on:click='handler($event)'>handle this</button> Commented Mar 20, 2018 at 4:09
  • Have you tried logging arguments inside handler to see what's coming in? Commented Mar 20, 2018 at 4:11
  • check my answer, there's a codepen example as well Commented Mar 20, 2018 at 4:16

2 Answers 2

2

Here's a codepen which I created.

My Vue Instance looks like:

new Vue({
    el: '#app',
    methods: {
        greet: (e) => {
            console.log(e.target.tagName);
        }
    },
})

and my html looks like this:

<div id="app">
    <button @click="greet">Yo, I'm a button</button>
</div>

and when i see the console, it looks like this:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

-1

Try it like this

v-on:click="handler($event)" 

1 Comment

There's too many reasons to -1 this, starting with Try it like this...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.