天天看点

vue项目笔记(29)-组件显示的动画

组件显示的动画

vue项目中,为优化用户体验,我们通常在组件显示的时候,我们加上动画效果。除了直接用transition标签作为组件的跟标签外,我们还可以把动画效果抽离成组件,方便复用。

FadeAnimation.vue

<template>
  <transition>
    <slot></slot>
  </transition>
</template>
<script>
  export default{
    name: 'FadeAnimation'
  }
</script>
<style scoped lang="stylus">
  .v-enter, .v-leave-to
    opacity 0

  .v-enter-active, .v-leave-active
    transition opacity 0.8s
</style>
           

本例中,我们对Banner.vue中的Commongallery.vue组件使用该动画效果。我们需要这样做:

import FadeAnimation from 'common/fade/FadeAnimation'           
<fade-animation>
      <common-gallery :imgs="imgs" v-show="showGallery" @close="handleGalleryClose"></common-gallery>
    </fade-animation>