10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

trにv-for

Posted at

trにv-forを使いたいが、カラム結合されている場合少し戸惑った。

trが複数で1行の場合など

<table>
  <tr>
    <td rowspan="2" bgcolor="#000"> </td>
    <td bgcolor="#f00"> </td>
    <td bgcolor="#0f0"> </td>
    <td bgcolor="#00f"> </td>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#0ff"> </td>
  </tr>
</table>

trが1つで1行なら以下でしたが、

<tr v-for="item in itemList" :key="item.id">
</tr>

templateを使う

<template v-for="item in itemList" :key="item.id">
</template>
'<template>' cannot be keyed. Place the key on real elements instead

templateはkeyが使えない様子。
ではどうするかというと以下のようにする。
keyはユニークにしないといけない。

<template v-for="item in itemList">
  <tr :key="item.id + '_1'">
  </tr>
 <tr :key="item.id + '_2'">
  </tr>
</template>
10
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?