<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<style>
li{
border:1px dashed #999999;
margin:5px;
line-height:35px;
padding-left:5px;
font-size:12px;
width:100%;
}
.v-enter,
.v-leave-to{
opacity:0;
transform:translateY(80px);
}
.v-enter-active,
.v-leave-active{
transition:all 0.6s ease;
}
.v-move{
transition:all 0.6s ease;
}
.v-leave-active{
position:absolute;
}
li:hover{
background:pink;
transition:all 0.4s ease;
}
</style>
</head>
<body>
<div id="app">
<div>
<label>
id:
<input type="text" v-model="id">
</label>
<label>
name:
<input type="text" v-model="name">
</label>
<input type="button" value="添加" @click="add">
</div>
<div>
<!--在实现列表过渡的时候,如果需要过渡的元素,是v-for循环渲染出来的,不能用transition包裹,需要使用transitionGroup-->
<!--如果要为v-for循环创建的元素设置动画,必须为每一个元素设置:key属性-->
<!--给transition-group添加appear属性,实现页面刚展示出来的时候的效果-->
<transition-group appear tag="ul">
<li v-for="(item,i) in list" :key="item.id">
{{item.id}}--{{item.name}}
<input type="button" value="删除" @click="del(i)">
</li>
</transition-group>
</div>
</div>
<script>
var vm=new Vue({
el:"#app",
data:{
id:"",
name:"",
list:[
{id:1,name:"赵高"},
{id:2,name:"秦桧"},
{id:3,name:"严嵩"},
{id:4,name:"魏忠贤"}
]
},
methods:{
add(){
this.list.push({id:this.id,name:this.name});
this.id="";
this.name="";
},
del(i){
this.list.splice(i,1);
}
}
})
</script>
</body>
</html>