vue中列表过渡22
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue中列表过渡22</title>
<script src="vue.js"></script>
<script src="velocity.js"></script>
<style type="text/css">
.v-enter,
.v-leave-to{
opacity: 0;
}
.v-enter-active,
.v-leave-active{
transition: opacity 1s;
}
</style>
</head>
<body>
<div id="app">
<!--3:使用group标签,相当于给里边的每一个div都套了一层transition-->
<transition-group>
<div v-for="item of list" :key="item.id">
{{item.title}}
</div>
</transition-group>
<button @click="handleBtnClick">add</button>
</div>
<script>
/*1:定义一个计数器*/
var count=0;
var vm=new Vue({
el:'#app',
data:{
list:[]
},
methods:{
/*2:当点击按钮的时候,每点击一次,list中加一个hello world*/
handleBtnClick:function(){
this.list.push({
id:count++,
title:'hello world'
})
}
}
})
</script>
</body>
</html>