首页 > 解决方案 > 如何在 v-if Vue.js 中添加类

问题描述

如果状态为非活动,我想以红色突出显示文本。下面是我的代码

<td v-for="option in selected_type" v-if="option.id == item.status"  v-bind:class="add class here">
    @{{ option.status }}
</td>

谢谢

标签: vue.js

解决方案


<td v-for="option in selected_type" :key="option.id" :class="{ inactive: item.status }">

我假设状态属性是一个布尔值(不知道你为什么还要将 id 与状态进行比较)

.inactive { color: red; }

推荐阅读