我有一个表,它根据列表中的项目数量动态显示行。当将项目添加到列表中时,表行会动画化(具有绿色背景)以显示正在添加新行,当我从列表中删除项目时,表行会动画化(具有红色背景)以显示显示正在删除。我显示一行消息 There are no more items in the list
当没有更多元素时。
我的问题是,当列表中没有更多项目时,列表为空时显示的表格行会使用我上面提到的绿色背景进行动画处理,当有项目时也是如此添加到列表中(从空),该行以红色背景动画
我的问题:是否可以忽略<transition-group>
下的单个元素的动画?
HTML:
<table class="table table-striped" id="item-table">
<thead>
<tr>
<th>Item</th>
<th>Description</th>
</tr>
</thead>
<tbody name="fade" is="transition-group">
<tr v-for="(item, index) in items" :key="item.id">
<td>
{{ item.name }}
</td>
<td class="text-center">
<button class="btn btn-primary" @click.prevent="removeItem(index, item.id)"><i class="fa fa-check"></i></button>
</td>
</tr>
<tr v-if="items.length == 0" class="text-center" key="noItems">
<td colspan="2">There are no more items in the list</td>
</tr>
</tbody>
</table>
CSS:
.fade-enter-active {
transition: opacity 1.5s;
background-color: #a1ec8e !important;
}
.fade-leave-active {
transition: opacity 1.5s;
background-color: tomato !important;
}
.fade-enter, .fade-leave-to {
opacity: 0
}
JS:
const App = new Vue({
el: "#app",
data() {
return {
items: [],
}
},
methods: {
addItem(item) {
this.items.push(item);
},
removeItem(index) {
this.items.splice(index, 1);
}
}
});
最佳答案
从你的 CSS 中删除 !important。如果没有它,您可以使用如下内容覆盖行样式:
.fade-enter-active[key="noItems"] {
background-color: yellow;
}
过渡组只是添加或删除子元素上的类,但动画样式仅由 css 控制。
关于javascript - VueJS - 是否可以禁用过渡组下特定元素的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45430543/