Click here to see an example where items smoothly move in a list when one item is removed. To achieve this effect, the element needs to be styled with:
.list-complete-leave-active {
position: absolute;
}
I'm curious as to why it doesn't work without this styling?
new Vue({
el: '#list-complete-demo',
data: {
items: [1,2,3,4,5,6,7,8,9]
},
methods: {
randomIndex: function () {
return Math.floor(Math.random() * this.items.length)
},
remove: function () {
this.items.splice(this.randomIndex(), 1)
}
}
})
.list-complete-item {
transition: all 1s;
display: inline-block;
margin-right: 10px;
}
.list-complete-leave-to {
opacity: 0;
transform: translateY(30px);
}
.list-complete-leave-active {
position: absolute;
}
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>
<div id="list-complete-demo" class="demo">
<button v-on:click="remove">Remove</button>
<transition-group name="list-complete" tag="p">
<span
v-for="item in items"
v-bind:key="item"
class="list-complete-item"
>
{{ item }}
</span>
</transition-group>
</div>