I have this simple example written in Vue.js.
// vue instance
var vm = new Vue({
el: "#app",
data: {
matrix: ["", "", "", "", "", "", "", "", ""],
},
methods: {
handleClick: function() {
console.log("event triggered");
}
}
})
* {
box-sizing: border-box;
}
#game-box {
width: 150px;
display: block;
margin: 0px auto;
padding: 0px;
background: green;
}
.grid-item {
float: left;
width: 33.333%;
height: 50px;
background: yellow;
border: 1px solid green;
margin: 0px;
text-align: center;
}
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
<div id="game-box">
<div v-for="(sign, index) in matrix" class="grid-item" @click="handleClick">
{{ sign }}
</div>
</div>
</div>
Is there any way to send data with click event (for example the index of the element that was clicked) in order to be handled by the handleClick
method doing something like this:
handleClick: function(index) {
console.log(index);
}
@click="handleClick(index)
should work, have you tried this way? working example jsfiddle.net/azs06/4ps1b4nk – azs06 Jan 26 at 22:07