2016-08-08 2 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) 
    } 
}) 
관련 문제