1

Suppose I have nested elements that are repeated with v-for like this:

<div id="container">
    <div v-for="i in 3">
       <div v-for="j in 3" v-on:click="clicked(i,j)">
         {{i+','+j}}
       </div>
    </div>
</div>

And the corresponding Javascript:

var vm = new Vue({
   methods:{
    clicked:function(i, j){
        //How to access the click event here?
    }
   },
   el:'#container'
})

If I use v-on:click="clicked" I can access the event (and the corresponding element) in the clicked function. But I want to supply the parameters i and j, how can I both access them and the click event? I want to be able to do this regardless of event (keyup, keydown, blur, focus etc).

1
  • 2
    supply $event as a param inside clicked($event, i, j) Commented Apr 7, 2017 at 9:15

1 Answer 1

2

To access event object send $event as parameter, Vue will assign the event object if $event named parameter is found in event handlers.

<div v-for="j in 3" v-on:click="clicked(i, j, $event)">
 {{i+','+j}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

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.