首页 > 其他 > 详细

Vue中多个元素或组件的过渡

时间:2019-12-21 14:30:13      阅读:83      评论:0      收藏:0      [点我收藏+]

1.因Vue的复用机制,此处动画不会执行,可给元素添加唯一key值来使vue对该元素不进行复用。

2.先进入执行还是先出去执行,可在<transition>元素上设置:mode="in-out"或者mode="out-in"

3.组件的过渡和普通元素的用法一致。

4.动态组件的过渡需在动态组件内绑定is属性。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue中多个元素或组件的过渡</title>
<script src="./vue.js"></script>
<style>
  .v-enter,v-leave-to{
     opacity:0;
  }
  .v-enter-active,.v-leave-active{
    transition:opacity 1s;
  }
  </style>
</head>
<body>
  <div id="root">
    <transition mode="in-out">
<!--      <div v-if="show" key="hello">hello world</div>
     <div v-else key="bye">Bye world</div> -->
     <component :is="type"></component>
     <child v-if="show"></child>
     <child-one v-else></child-one>
    </transition>
    <button @click="handleClick">切换</button>
   </div>
   <script>
    Vue.component(child,{
      template:<div>child</div>
    })
    Vue.component(child-one,{
      template:<div>child-one</div>
    })
    var vm=new Vue({
      el:#root,
      data:{
        type:child
      },
      methods:{
        handleClick:function(){
          this.type=this.type===child?child-one:child
        },
        handleBeforeEnter:function(el){
          el.style.color="red"

        },
        handleEnter:function(el,done){
          setTimeout(() =>{
            el.style.color=green
           
          },2000)
          setTimeout(() =>{
            done()
          },4000)
        },
        handleAfterEnter:function(el){
          el.style.color=#000
        }
      }
    })
   </script>
</body>
</html>

Vue中多个元素或组件的过渡

原文:https://www.cnblogs.com/tengteng0520/p/12076688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!