【发布时间】:2021-07-19 06:13:04
【问题描述】:
在the example in the docs 之后,我使用transition-group 作为项目列表。奇怪的是,它在项目出现时起作用(enter),而不是在它们消失时(leave),这意味着它们在出现时以动画方式向下滑动,但在没有动画的情况下立即消失:leave 动画失败。为什么?
<template>
<div v-if="notifications.length">
<transition-group name="notifications">
<span
v-for="notification in notifications"
:key="notification.id"
>
<!-- content -->
</span>
</transition-group>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
computed: {
...mapState({
notifications: state => state.notifications.notifications
})
}
}
</script>
<style lang="scss" scoped>
.notifications-enter-active,
.notifications-leave-active {
transition: all 0.5s;
}
.notifications-enter {
transform: translateY(-100%);
}
.notifications-leave-to {
opacity: 0;
}
</style>
商店
export const mutations = {
DELETE_NOTIFICATION (state, id) {
state.notifications.splice(
state.notifications.findIndex(item => item.id === id),
1
)
}
}
【问题讨论】:
标签: vue.js transition