码迷,mamicode.com
首页 > 其他好文 > 详细

vue动画的封装

时间:2020-02-21 21:55:05      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:fun   hand   and   timeout   var   script   for   methods   out   

<body>
  <div id="root">
    <fade :show=‘show‘>
      <h1>hello world</h1>
    </fade>
    <button @click=‘handleBtnClick‘>tooggle</button>
  </div>
  <script>
    Vue.component(fade,{
      props:[show],
      template:`
      <transition @before-enter=handleBeforeEnter @enter=handleEnter>
        <slot v-if=show></slot>  
      </transition>
      `,
      methods:{
        handleBeforeEnter:function(el){
          el.style.color=red
        },
        handleEnter:function(el,done){
          setTimeout(()=>{
            el.style.color=green;
            done();
          },2000)
        }
      }
    })
    var vm=new Vue({
      el:#root,
      data:{
        show:true
      },
      methods:{
        handleBtnClick:function(){
          this.show=!this.show;
        }
      }
    })
  </script>
</body>

借助插槽slot和动画钩子实现

vue动画的封装

标签:fun   hand   and   timeout   var   script   for   methods   out   

原文地址:https://www.cnblogs.com/em2464/p/12343232.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!