简体   繁体   English

我是否缺少vue路由器转换的内容?

[英]Am I missing something for vue router transitions?

I'm trying to have a transition between my components in Vue, this is my code: 我正在尝试在Vue中的组件之间进行转换,这是我的代码:

<template>
  <div id="app">
    <router-link to="/">Go to home</router-link>
    <router-link to="Register">Go to register</router-link>
    <transition name="fade">
      <router-view></router-view>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

<style scoped>
  .fade-enter-active, .fade-leave-active {
    transition: opacity .5s;
  }
  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
    opacity: 0;
  }
}

However, the transition is not working at all. 但是,过渡根本无法进行。 It correctly switches from component to component, but without transition. 它可以正确地在组件之间切换,但是没有过渡。

I've read the Vue and Vue Router docs, and as far as I know I'm doing exactly what the docs are saying. 我已经阅读了Vue和Vue Router文档,据我所知,我正在按照文档所说的去做。 Anyone knows what I'm missing or doing wrong? 有人知道我缺少什么或做错了什么吗?

Something defines the .fade-enter and .fade-appear classes. 定义了.fade-enter.fade-appear类。 You can see this happening if you have a link that calls the debugger after one tick, and inspect the applied styling: 如果您有一个链接在打勾后调用调试器,并检查了所应用的样式,则可以看到这种情况:

stopThings () {
  this.$router.push({
    name: 'Login'
  });

  this.$nextTick(() => {
    debugger;
  });
}

Because the initial state is incorrect, the transition does not do anything. 由于初始状态不正确,因此过渡不会执行任何操作。

Rename your transition and your transition classes to literally anything else, eg myfade and your transition works as expected. 将转换和转换类重命名为其他名称,例如myfade ,转换将按预期工作。

The transitions, as far as I can see from the code shared, looks fine. 从共享代码中可以看到,过渡看起来不错。 It could be that the transitions are happening outside of the view. 过渡可能发生在视图之外。 During the transition, both elements are visible 在过渡期间,两个元素均可见

here is an example of adding a wrapper with relative and absolute positionsing 这是添加具有相对和绝对位置的包装器的示例

<template>
  <div id="app">
    <router-link to="/">Go to home</router-link>
    <router-link to="Register">Go to register</router-link>
    <div class="content">
      <transition name="fade">
        <router-view></router-view>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  name: "App"
};
</script>

<style scoped>
.content {
  position: relative;
}
.content > * {
  position: absolute;
  top: 0;
  left: 0;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>

编辑路由器示例(SO)

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

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