【发布时间】:2020-02-10 17:31:15
【问题描述】:
以下代码的数组项未呈现在正确的列中:
<div id="app">
<v-app>
<v-simple-table>
<template v-slot:default>
<thead>
<tr>
<th class="text-left">Mon </th>
<th class="text-left">Tue</th>
<th class="text-left">Wed </th>
<th class="text-left">Thu</th>
<th class="text-left">Fri </th>
<th class="text-left">Sat </th>
<th class="text-left">Sun</th>
</tr>
</thead>
<tbody>
<tr>
<template v-for="item in schedules">
<td v-if="days.includes(item.day)" class="text-left">{{item.from_time}}-{{item.to_time}}</td>
<td v-else class="text-left">-</td>
</template>
</tr>
</tbody>
</template>
</v-simple-table>
</v-app>
</div>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
schedules: [
{ day: 1, from_time: '15:00', to_time: '13:00' },
{ day: 6, from_time: '16:00', to_time: '16:30' },
],
days: [1,2,3,4,5,6,7]
})
})
</script>
schedules(第 6 天)中的第二项应放在 Sat 列,而不是 Tue 列。
注意:
- 如果计划的索引日期 = 1,则时间放在列 Mon
- 如果计划的索引日期 = 2,则将时间放在 星期二 列中
- 如果日程表的索引日期 = 3,则时间放在列星期三
等等……
如何按日期索引在工作日列中呈现schedules 项目?也许解决方案是将schedules 和days 合并为一个数据对象。
【问题讨论】:
标签: arrays vue.js vuejs2 vue-component vuetify.js