signed

QiShunwang

“诚信为本、客户至上”

Vue-Router-过渡动效

2021/4/26 20:34:19   来源:

官方文档: 地址

1.自己写一个动效

<div class="demo">
      <transition>
        <router-view></router-view>
      </transition>
</div>

.demo {
    width: 500px;
    height: 500px;
    border: 1px solid #000;
    margin: 20px auto;
    .v-enter {
      opacity: 0;
      transform: translateX(100%);
      position: absolute;
    }
    .v-leave-to {
      opacity: 0;
      transform: translateX(-100%);
      position: absolute;
    }
    .v-enter-active,
    .v-leave-active {
      transition: all 1s ease;
    }
  }

2.通过animate.css解决

 <link href="https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css" rel="stylesheet">
 <div id="box">
    <p>
      <router-link to="/home">home</router-link>
      <router-link to="/news">news</router-link>
    </p>
    <transition enter-active-class="animated rollIn" leave-active-class="animated rollOut" :duration="500">
      <router-view></router-view>
    </transition>
  </div>