Answer the question
In order to leave comments, you need to log in
How to deal with an array in one table cell? How to make rowspan in Vue template?
There is data:
tempData: [
{
name: 'Vasya',
age: 22,
links: ['http://facebook.com', 'http://google.com', 'http://vk.com'],
},
{
name: 'Petya',
age: 43,
links: ['http://facebook.com', 'http://google.com', 'http://vk.com'],
},
{
name: 'Stapan',
age: 52,
links: ['http://facebook.com', 'http://google.com', 'http://vk.com'],
},
],
links
Answer the question
In order to leave comments, you need to log in
I see the following options:
<template v-for="row in rows">
<tr>
<template v-for="(item, k) in row">
<td v-if="k === 'links'">{{ item[0] }}</td>
<td v-else :rowspan="row.links.length">{{ item }}</td>
</template>
</tr>
<tr v-for="link in row.links.slice(1)">
<td>{{ link }}</td>
</tr>
</template>
<template v-for="row in rows">
<tr>
<td
v-for="k in [ 'name', 'age' ]"
:rowspan="row.links.length + 1"
>{{ row[k] }}</td>
</tr>
<tr v-for="link in row.links">
<td>{{ link }}</td>
</tr>
</template>
<tr v-for="row in rows">
<td v-for="item in row">
<template v-if="item instanceof Array">
<div v-for="n in item">{{ n }}</div>
</template>
<template v-else>
{{ item }}
</template>
</td>
</tr>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question