2016-08-08 5 views
0

以下のイベントハンドラに列のインデックスを渡すことができます。行と列の両方のセルインデックスを渡すことは可能ですか?セルのインデックスをイベントハンドラに渡す

<table id="app"> 
<tr v-for="row in rows"> 
    <td v-for="cell in row", @click="getCol($index)"> 
    {{cell}} 
    </td> 
</tr> 
</table> 

new Vue({ 
    el: '#app', 
    data: { 
    rows: [ 
     [11, 12, 13], 
     [21, 22, 23]  
    ] 
    }, 
    methods: { 
    getCol: (index) => console.log(index) 
    } 
}) 
+1

あなたは解決策として、あなたのソリューションを投稿し、解決としてマークすることはできますか? –

答えて

1

@Solution

<table id="app"> 
<tr v-for="(i, row) in rows"> 
    <td v-for="(j, cell) in row", @click="getCell(i, j)"> 
    {{cell}} 
    </td> 
</tr> 
</table> 

new Vue({ 
    el: '#app', 
    data: { 
    rows: [ 
     [11, 12, 13], 
     [21, 22, 23]  
    ] 
    }, 
    methods: { 
    getCell: (i, j) => console.log(i, j) 
    } 
}) 
関連する問題