多个元素的过渡
<style>
  .v-enter,.v-leave-to{
    opacity: 0;
  }
  .v-enter-acitve,.v-leave-active{
    opacity: opacity 1s;
  }
</style>
<div id='app'>
  <transition>
    <div v-if='show'>hello world</div>
    <div v-else>bye world</div>
  </transition>
  <button @click='handleClick'>切换</button>
</div>
<script>
var vm = new Vue({
  el:'#app',
  data:{
    show:true
  },
  methods:{
    handleClick:function(){
      this.show = !this.show;
    }
  }
})
</script>
按照之前的写法方式,渐隐渐出的效果并没有出现该有的效果,那么为什么呢?
在if else两个元素切换的时候,会尽量的复用dom,正是vue,dom的复用,导致动画的效果不会出现,如果想要vue不去复用dom,之前也说过,怎么做呢,给两个div不同的key值就行了
<div v-if='show' key='hello'>hello world</div>
<div v-else key='bye'>bye world</div>
这样就可以有个明显的动画效果,,多个元素过渡动画的效果
transition还提供了一个mode属性,in-out是先显示再隐藏,out-in是先隐藏再显示
多个组件的过渡
<style>
  .v-enter, .v-leave-to {
    opacity: 0;
  }
  .v-enter-acitve, .v-leave-active {
    transition: opacity 1s;
  }
</style>
<div id='app'>
  <transition mode='out-in'>
    <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:'#app',
  data:{
    show:true
  },
  methods:{
    handleClick:function(){
      this.show = !this.show;
    }
  }
})
</script>
这个就是多个组件的过渡,采用的是上面的方式,替换子组件,那么我们换一种方式,用动态组件
<style>
  .v-enter, .v-leave-to {
    opacity: 0;
  }
  .v-enter-acitve, .v-leave-active {
    transition: opacity 1s;
  }
</style>
<div id='app'>
  <transition mode='out-in'>
    <component :is='type'></component>
  </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:'#app',
  data:{
    type:'child'
  },
  methods:{
    handleClick:function(){
      this.type = (this.type === 'child' ? 'child-one' : 'child')
    }
  }
})
</script>
这样也实现了多个组件的过渡效果

最新文章

  1. Filco minila 的蛋疼。
  2. Linux - 获取Shell命令帮助信息
  3. [开发笔记]-Windows Service服务相关注意事项
  4. [React] Higher Order Components (replaces Mixins)
  5. HDU 4135 Co-prime
  6. java获取当前方法
  7. MySQL的三层架构之一----连接层
  8. 1005. 继续(3n+1)猜想 (25) (ZJUPAT 数学)
  9. (转)java并发之Executor
  10. SSM Spring+SpringMVC+mybatis+maven+mysql环境搭建
  11. Vue 爬坑之路(八)—— 使用 Echarts 创建图表
  12. ie兼容问题记录
  13. tensorflow学习笔记1:导出和加载模型
  14. List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user
  15. python 中 打印及格式化字符串的相关方法
  16. python+ajaxFileUpload 无刷新上传文件
  17. Linux 命令之删除命令
  18. [UOJ#276][清华集训2016]汽水[分数规划+点分治]
  19. 71. Simplify Path(M)
  20. 关于面试总结2-SQL学生表

热门文章

  1. python+selenium 元素被定位到而且click()也提示执行成功,但是页面就是没有变化和跳转。
  2. 2.1 Rust概念
  3. Linux IPC 共享内存
  4. input校验不能以0开头的数字
  5. 智能时代的到来,企业APP给企业带来的好处
  6. Tree UVA - 548(二叉树递归遍历)
  7. Map集合练习之对字符串中字母出现的次数求和
  8. 虚拟机扩容(/dev/mapper/centos-root 空间不足)
  9. Swift-数组
  10. Spring课程 Spring入门篇 3-2 Spring bean装配(上)之bean的生命周期