<router-view v-slot="{ Component }"><transition name="fade" mode="out-in" appear><keep-alive><component :is="Component" /></keep-alive></transition>
</router-view>/* 路由切換動畫 */
/* fade-transform */
.fade-leave-active,
.fade-enter-active {transition: all 0.5s;
}/* 可能為enter失效,拆分為 enter-from和enter-to */
.fade-enter-from { opacity: 0;transform: translateY(-30px);
}
.fade-enter-to { opacity: 1;transform: translateY(0px);
}.fade-leave-to {opacity: 0;transform: translateY(30px);
}
transition 標簽元素有一個mode屬性,用于設置動畫過渡效果。默認是同時進行元素的進入和離開。元素絕對定位position: absolute;不會有錯位問題。
in-out,新元素先進行過渡進入,完成之后當前元素過渡離開。
out-in,當前元素先過渡離開,完成之后新元素過渡進入。在transition標簽還有一個appear屬性
是否對初始渲染使用過渡。 * 默認:false