首页 > 解决方案 > 如果 v-for 的索引不同于 2 个值,则将行跨度设为 2

问题描述

我有下表:

<table class="table table-condensed table-sm table-striped table-bordered" id="list">
    <thead>
        <tr>
            <th v-for="(column, index) in columns" :key="index" :rowspan="{ '2': index != 'new_value' || 'old_value' }">
                {{ column }}
            </th>
        </tr>
    </thead>
    <tbody>
        <tr v-for="(entry, index) in results" :key="index">
            <td v-for="(key, index) in columns" :key="index">
                {{ entry._source[index] }}
            </td>
        </tr>
    </tbody>
</table>

我希望表头的行跨度不是new_valueold_value为 2,但是在当前代码中,表头有一个[object Object]而不是一个数字:

<th rowspan="[object Object]">User</th>

我应该怎么办?

标签: javascriptvue.js

解决方案


rowspan属性需要一个数字而不是一个对象。尝试:

:rowspan="index !== 'new_value' && index !== 'old_value' ? 2 : 1"

推荐阅读