简体   繁体   English

Vuejs 路由器转换不会发生

[英]Vuejs router transition doesn't happen

I've just started learning vue and tried to do a router transition.我刚刚开始学习 vue 并尝试进行路由器转换。 However the above code doesn't have any transitions when I switch between pages.但是,当我在页面之间切换时,上面的代码没有任何转换。 Any idea why?知道为什么吗? Extra line since stackoverflow does not let me submit the question otherwise.额外的行,因为 stackoverflow 不允许我以其他方式提交问题。

<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link><br><br>
    </div>
    <transition name="fade" mode="out-in">
      <router-view></router-view>
    </transition>
  </div>
</template>
<script>

</script>
<style>
body {
  background-color: #00ffcc;
  margin: 0;
  padding: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  overflow: hidden;
  width: 100vw;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}

.fade-enter, .fade-leave-to {
  opacity: 0;
  transform: translateX(2em);
}

.fade-enter-active, .fade-leave-active {
  transition: all .3 ease;
}
</style>

The issue seems to be with your CSS code, it should be transition: all 0.3s ease .问题似乎与您的 CSS 代码有关,它应该是transition: all 0.3s ease Here is a working example这是一个工作示例

 const Home = { template: '<div>Home</div>' } const Foo = { template: '<div>Foo</div>' } const router = new VueRouter({ mode: 'hash', routes: [ { path: '/', component: Home }, { path: '/foo', component: Foo } ] }) new Vue({ router, el: '#app', data: { msg: 'Hello World' } })
 body { background-color: #00ffcc; margin: 0; padding: 0; } #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; overflow: hidden; width: 100vw; } #nav { padding: 30px; } #nav a { font-weight: bold; color: #2c3e50; } #nav a.router-link-exact-active { color: #42b983; } .router-link-active { color: red; } .fade-enter, .fade-leave-to { opacity: 0; transform: translateX(2em); } .fade-enter-active, .fade-leave-active { transition: all 0.3s ease; }
 <script src="https://npmcdn.com/vue/dist/vue.js"></script> <script src="https://npmcdn.com/vue-router/dist/vue-router.js"></script> <div id="app"> <router-link to="/">/home</router-link> <router-link to="/foo">/foo</router-link> <transition name="fade" mode="out-in"> <router-view></router-view> </transition> </div>

Here, is a jsfiddle of the above code .这里,是上述代码的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM