Vue <transition> 多个组件的过渡案例2

这篇博客展示了如何在Vue.js应用中使用`<transition>`组件实现多个组件间的过渡动画,结合animate.css库,创建了`animate__backInDown`和`animate__backOutDown`的进入和离开动画效果。同时,文章提到了在特定情况下可能出现的滚动条闪烁问题,并给出了 scoped CSS 的解决方案,确保样式只在当前组件内生效。
<!-- Vue <transition> 多个组件的过渡案例2 -->

<template>
  <div class="page">
    <div class="text-center">
      <input type="radio" v-model="view" value="componentA">a
      <input type="radio" v-model="view" value="componentB">b
    </div>
    <transition
      enter-active-class="animate__animated animate__backInDown"
      leave-active-class="animate__animated animate__backOutDown animate__faster"
      mode="out-in">
      <!--
      注意:animate__backOutDown动画,在高度不够的情况下,可能会出现滚动条闪烁的bug
      -->
      <component :is="view"></component>
    </transition>
  </div>
</template>

<script>
  import componentA from '@/components/componentA'
  import componentB from '@/components/componentB'

  export default {
    name: 'HelloWorld',
    data() {
      return {
        view: 'componentA'
      }
    },
    components: {
      componentA, componentB
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
  body {
    margin: 0;
  }
  /*
  /deep/ 为深度作用选择器
  正常情况下,在scoped作用域下,.text-center无法影响到子组件componentA和componentB的样式
  如果不加scoped又会影响到全局样式
  此时,使用/deep/深度作用选择器,就可以在子组件中使用.text-center了

  具体教程可参考:
  https://www.jb51.net/article/188038.htm
  */
  /deep/ .text-center {
    text-align: center;
  }
</style>
//在main.js中全局引入css
// animate.css官方文档 https://animate.style/
import '@/assets/css/animate.min.css'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值