【发布时间】:2019-12-20 17:51:51
【问题描述】:
我使用v-data-table 来管理电子邮件。用户可以单击一行,然后会出现一个包含电子邮件详细信息的弹出窗口。
我想要的东西:
单击这些行后,我希望将行标记为“已读”(因此 css 粗体/非粗体)。
问题:
我已经在这里找到了一些示例(但仅适用于较旧的 Vuetify 版本):Vuetify - How to highlight row on click in v-data-table
这个示例(以及我发现的所有其他示例)使用 v-data-table 的扩展代码 - 比如:
<v-data-table :headers="headers" :items="desserts" class="elevation-1">
<template v-slot:items="props">
<tr @click="activerow(props.item)" :class="{'primary': props.item.id===selectedId}">
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
<td class="text-xs-right">{{ props.item.carbs }}</td>
<td class="text-xs-right">{{ props.item.protein }}</td>
<td class="text-xs-right">{{ props.item.iron }}</td>
</tr>
</template>
</v-data-table>
所以扩展代码是:
<template v-slot:items="props">
<tr @click="activerow(props.item)" :class="{'primary': props.item.id===selectedId}">
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
<td class="text-xs-right">{{ props.item.carbs }}</td>
<td class="text-xs-right">{{ props.item.protein }}</td>
<td class="text-xs-right">{{ props.item.iron }}</td>
</tr>
</template>
但是自从我使用 Vutify 版本 2 之后
<template slot="headers" slot-scope="props">
和
<template slot="items" slot-scope="props">
里面
<v-data-table>
似乎被忽略了。
Vuetify 2 提供了一些新的插槽,但我还没有找到如何在这个示例中使用它们。
谁能提供 Vuetify >= 2.0 的示例? 相信我,目前还没有更高版本可用 - 在 CodePen 或 JSFiddle 等任何开发环境中都没有。
【问题讨论】:
-
你也许可以使用
click:row事件,但是如果你想在刷新页面时保持点击状态,你可能需要使用v-slot方案。 -
嗨,Flame,我也使用
click:row,但还没有解决方案。如果您能在 CodePen 中提供一个可行的示例,那就太好了。 -
尝试以下方式:
@click="$event.target.classList.add('clicked')"为您刚刚单击的元素添加clicked类
标签: javascript css vue.js vuetify.js