Vue中多元素过渡特效的解决方案

2020-06-16 06:51:03易采站长站整理

</transition>
</div>
<script>
new Vue({
el: '#demo',
data: {
isOn: true
},
})
</script>

多组件过渡

多个组件的过渡简单很多,不需要使用 key 特性。相反,只需要使用动态组件

下面是一个例子


<style>
.fade-enter,.fade-leave-to{opacity:0;}
.fade-enter-active,.fade-leave-active{transition: .5s;}
</style>
<div id="example">
<button @click="change">切换页面</button>
<transition name="fade" mode="out-in">
<component :is="currentView"></component>
</transition>
</div>
<script>
new Vue({
el: '#example',
data:{
index:0,
arr:[
{template:`<div>ComponentA</div>`},
{template:`<div>ComponentB</div>`},
{template:`<div>ComponentC</div>`}
],
},
computed:{
currentView(){
return this.arr[this.index];
}
},
methods:{
change(){
this.index = (++this.index)%3;
}
}
})

更多关于Vue过渡动画的文章大家可以查看下面的相关链接