My JSON data looks like this:
{
"data":{
"1":{
"color":"red",
"size":"big"
},
"2":{
"color":"red",
"size":"big"
},
"3":{
"color":"red",
"size":"big"
},
"4":{
"color":"red",
"size":"big"
},
"5":{
"color":"red",
"size":"big"
}
}
}
I am using the following vue
code to display it:
<template>
...
<template v-for="(obj, pos) in this.breakdown" :key="pos">
<table class="table-auto" >
<thead>
<tr>
<th class="px-4 py-2">Property</th>
<th class="px-4 py-2">Value</th>
</tr>
</thead>
<tbody>
<template v-for = "(obj2, pos2) in obj" :key="pos2">
<tr>
<td class="border px-4 py-2">
{{pos2}}
</td>
<td class="border px-4 py-2">
{{obj2}}
</td>
</tr>
</template>
</tbody>
</table>
</template>
...
</template>
I encountered an error that says
'<template>' cannot be keyed. Place the key on real elements
. Changing template
to span
or div
resolves the error, but ruins the styling. I've heard that only the template
tag can achieve the desired results without a wrapper element. Now, I'm unsure of how to adjust the v-for
loops to eliminate the error.