【发布时间】:2021-05-13 14:32:17
【问题描述】:
我在 vuetify 中有一个表,我想为其中的 14 列创建一个模板。而不是像这样制作 14 个不同的模板:
<v-data-table disable-pagination
:headers="headers"
:items="users"
:search="search"
:hide-default-footer="true"
>
<template v-slot:[`item.date_0`]="{ item }">
<ScheduleIcon :item="item.date_0" />
</template>
<template v-slot:[`item.date_1`]="{ item }">
<ScheduleIcon :item="item.date_1" />
</template>
<template v-slot:[`item.date_2`]="{ item }">
<ScheduleIcon :item="item.date_2" />
</template>
</v-data-table>
我想创建一个索引为 0-13 的 v-for 循环,同时在 slot 和 props 变量中使用该索引值。像这样的东西是伪代码:
<template v-slot:[`item.date_INDEX`]="{ item }" v-for="index in 13" :key="index">
<ScheduleIcon :item="item.date_INDEX" />
</template>
我该怎么做? v-for 给我以下错误:
<template> cannot be keyed. Place the key on real elements instead.
【问题讨论】:
标签: vue.js vuetify.js