JSFiddle - React, Tailwind, and code Playground
HTML
<div id="app">
<input type="text" v-model="newtodo">
<button v-on:click="addTodo">add</button>
<ul>
<li v-for="todo in todos" transition="zj">
{{todo.text}}
<button v-on:click="rmTodo($index)">Χ</button>
</li>
</ul>
</div>
CSS
li button{
width:2em;
height:18px;
}
.zj-transition{
height:2em;
transition: all 0.5s ease;
}
.zj-enter, .zj-leave {
height:0;
opacity:0;
}
JavaScript
new Vue({
el: "#app",
data: {
newtodo: '',
todos: []
},
methods: {
addTodo: function() {
if (this.newtodo) {
this.todos.push({
text: this.newtodo
});
}
this.newtodo = '';
},
rmTodo: function(index) {
this.todos.splice(index, 1);
}
}
});
Vue.transition('stagger', {
stagger: function (index) {
// 每个过渡项目增加 50ms 延时
// 但是最大延时限制为 300ms
return Math.min(300, index * 50)
}
})