transition-group的使用
代码:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./lib/vue-2.4.0.js"></script>
<script src="./lib/iview.min.js"></script>
<script src="./lib/vue-resource-1.3.4.js"></script>
</head>
<body>
<div id="app">
<!-- 通过v-for渲染的dom,需要用<transition-group></transition-group>包围起来,还有设定:key -->
<transition-group name="myGroup">
<li class="mytable" v-for="(item,index) in list" :key="item.id" @click="del(index)">
{{item.id}}----{{item.name}}----{{item.nickname}}
</li>
</transition-group>
</div>
</body>
<script>
Vue.http.options.root = 'http://localhost:3000/'
var vm = new Vue({
el:'#app',
data() {
return {
list:[],
}
},
created() {
this.$http.get('list').then(res => {
this.list = res.data;
})
},
methods:{
del(i){
this.list.splice(i,1);
}
},
})
</script>
<style>
.mytable {
border: 1px dashed silver;
line-height: 30px;
}
.mytable:hover {
background-color:rgb(228, 230, 225);
}
.myGroup-enter, .myGroup-leave-to{
opacity: 0;
transform: translateY(80px);
}
.myGroup-enter-active, .myGroup-leave-active {
transition: all 2s ease;
}
/* v-move和v-leave-active实现删除一行,后面元素移位的动画效果 */
.myGroup-move{
transition: all 0.6s ease;
}
.myGroup-leave-active{
position: absolute;
}
</style>
</html>
效果