javascript - VueJS v-for access both parameters and event object on event -
suppose have nested elements repeated v-for
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 corresponding javascript:
var vm = new vue({ methods:{ clicked:function(i, j){ //how access click event here? } }, el:'#container' })
if use v-on:click="clicked"
can access event (and corresponding element) in clicked
function. want supply parameters , j, how can both access them , click event? want able regardless of event (keyup, keydown, blur, focus etc).
to access event object send $event
parameter, vue assign event object if $event
named parameter found in event handlers.
<div v-for="j in 3" v-on:click="clicked(i, j, $event)"> {{i+','+j}} </div>
Comments
Post a Comment