您需要填写表格的单元格。
为了填充所有单元格,我使用了 queryselectorall。但是数组出来是空的。
<table>
<tbody :id="`table-${id}`">
<tr v-for="(row, index) in table[0]"
:key="index + 'key'"
class="rows">
<td v-for="(cell, index) in table[1]" class="cell"
:key="index" >
</td>
</tr>
</tbody>
clicked () {
const tableWrapper = document.querySelector('#table-' + this.id)
const tds = tableWrapper.querySelectorAll('td')
console.log('td', tableWrapper, tds)
tds.forEach(td => {
console.log('tds', td)
})
}
您可以使用refs。有了它,就可以获得dom元素。但我不建议经常使用它。
你可以在这里阅读
在此示例中,当页面加载时,使用 refs 设置焦点