<!DOCTYPE?html> <html> <head> ????<title></title> ????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> ????<link?rel="stylesheet"?type="text/css"?href="./animate.css"> ????<script?src="./vue.js"></script> ????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?--> ???? </head> <body> ????<div?id="root"> ????????//性能考慮,盡量不用index作為key值?<br> ????????<div?v-for="(item)?of?list"?:key="item.id"> ????????????{{item.title}} ????????</div> ????????<button?@click="handBtnClick">add</button> ????</div> ????<script?type="text/javascript"> ????????var?count?=?0; ????????var?vm?=?new?Vue({ ????????????el:?"#root", ????????????data:?{ ????????????????list:?[] ????????????}, ????????????methods:?{ ????????????????handBtnClick:?function()?{ ????????????????????this.list.push({ ????????????????????????id:?count++, ????????????????????????title:?"hello" ????????????????????}); ????????????????} ????????????} ????????}); ????</script> </body> </html>
之前是對單個或多個元素之間做切換動畫效果,現(xiàn)在,對一個列表過渡效果,用標簽<transition-group>:
創(chuàng)新互聯(lián)專注于海滄企業(yè)網(wǎng)站建設,成都響應式網(wǎng)站建設公司,商城網(wǎng)站制作。海滄網(wǎng)站建設公司,為海滄等地區(qū)提供建站服務。全流程按需定制制作,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務
<!DOCTYPE?html> <html> <head> ????<title></title> ????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> ????<link?rel="stylesheet"?type="text/css"?href="./animate.css"> ????<script?src="./vue.js"></script> ????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?--> ????<style?type="text/css"> ????????/*因為沒有給它命名,所以用默認v開頭的class名*/ ????????.v-enter,?.v-leave-to?{ ????????????opacity:?0; ????????} ????????.v-enter-active,?.v-leave-active?{ ????????????transition:?opacity?1s; ????????} ????</style> </head> <body> ????<div?id="root"> ????????//性能考慮,盡量不用index作為key值?<br> ????????<transition-group> ????????????<div?v-for="(item)?of?list"?:key="item.id"> ????????????????{{item.title}} ????????????</div> ????????</transition-group> ????????<button?@click="handBtnClick">add</button> ????</div> ????<script?type="text/javascript"> ????????var?count?=?0; ????????var?vm?=?new?Vue({ ????????????el:?"#root", ????????????data:?{ ????????????????list:?[] ????????????}, ????????????methods:?{ ????????????????handBtnClick:?function()?{ ????????????????????this.list.push({ ????????????????????????id:?count++, ????????????????????????title:?"hello" ????????????????????}); ????????????????} ????????????} ????????}); ????</script> </body> </html>
為啥上面的效果是增加的都有漸顯效果呢?
用一對<transition-group>標簽包裹
<transition-group>
????<div>hello</div>
????<div>hello</div>
????<div>hello</div>
</transition-group>
相當于每一個都用一對<transition>標簽包裹
<transition>
????<div>hello</div>
</transition>
<transition>
????<div>hello</div>
</transition>
<transition>
????<div>hello</div>
</transition>
當前標題:Vue中的列表過渡
網(wǎng)站鏈接:http://m.newbst.com/article40/jeeeho.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、品牌網(wǎng)站建設、微信小程序、搜索引擎優(yōu)化、自適應網(wǎng)站、電子商務
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)