目前在 Vue 中使用转换时,我面临的问题是页面上的某些组件会立即消失,而其余组件会随着整个页面正常淡出。
这是我的过渡设置为最小的可重现示例,在这里工作Codepen
您可以看到当从Home
路由切换到任何其他路由时,按钮会立即消失,而视图的其余部分会根据使用 css 设置的淡入淡出属性(和 vue 过渡)消失.
// https://github.com/groloop/vuejs-2-series
Vue.use(Vuetify);
Vue.use(VueRouter);
var Home = {
template: '<div> <h2>Home</h2> <v-tooltip left> <template v-slot:activator="{ on }"> <v-btn color="primary" dark v-on="on">Left</v-btn> </template> <span>Left tooltip</span> </v-tooltip> </div>'
}
var AboutUs = {
template: '<h2>About Us</h2>'
}
var Contact = {
template: '<h2>Contact</h2>'
}
var NotFound = {
template: '<h2>Not Found</h2>'
}
var router = new VueRouter({
history: false,
routes: [
{ path: '/', name: 'home', component: Home },
{ path: '/about-us', name: 'about-us', component: AboutUs },
{ path: '/contact', name: 'contact', component: Contact },
{ path: '*', name: 'not-found', component: NotFound }
],
});
new Vue({
el: '#app',
router: router
});
.fade-enter-active,
.fade-leave-active {
transition-duration: 0.5s;
transition-property: opacity;
transition-timing-function: ease-in;
}
.fade-enter-active {
transition-delay: .5s;
}
.fade-enter,
.fade-leave-active {
opacity: 0
}
<link href="https://unpkg.com/vuetify@1.5.16/dist/vuetify.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script src="https://unpkg.com/vuetify@1.5.16/dist/vuetify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.10/vue.js"></script>
<div id="app">
<v-toolbar>
<v-toolbar-title>TEST</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items>
<v-btn flat href="#/">Home</v-btn>
<v-btn flat href='#/about-us'>About us</v-btn>
<v-btn flat href='#/contact'>Contact</v-btn>
<v-btn flat href='#/test'>Test</v-btn>
</v-toolbar-items>
</v-toolbar>
<transition name="fade" mode="out-in">
<router-view></router-view>
</transition>
</div>