【问题标题】:Vue Component height transition on route change路由更改时的Vue组件高度转换
【发布时间】:2021-03-16 01:57:24
【问题描述】:

我正在尝试对我的英雄应用过渡幻灯片效果。英雄的高度在主页上是 100vh,其余页面上是一半。我尝试了很多方法,但我无法让它发挥作用。我已经设置了一个 $route 观察程序,它将具有相应高度属性的特定类应用于当前页面。在页面之间导航时,没有应用于英雄高度变化的过渡。请帮助我几天来一直试图解决这个问题。我正在使用 Vuejs 3 和 Buefy。

HTML

<transition name="my-slide">
<section class="hero" :class=" 'is-fullheight': heroFull ">
...
</section>
</transition>
<script>
export default {
    name: "Hero",
    data() {
        return {
            heroFull: false,
        };
    },
    watch: {
        $route() {
            if (this.$route.path === "/") {
            this.heroFull = true;
            console.log("its at home");
        } else {
            this.heroFull = false;
            console.log("its not at home");
                }
            }
        }
    };
</script>

CSS

.hero {
    transition: height 0.3s !important;
}

.hero.fullheight {
    min-height: 100vh;
}

.my-slide-enter-active,
.my-slide-leave-active {
    transition: height 0.3s 
}

.my-slide-enter-from,
.my-slide-leave-to {
    height: auto
}

.my-slide-enter-to,
.my-slide-leave-from {
    height: 100vh
}

【问题讨论】:

标签: javascript css vue.js frontend vuejs3


【解决方案1】:

尝试在updated钩子上添加验证,当组件发生变化时,类似于:

export default {
  name: "Hero",
  data() {
    return {
        heroFull: false,
    };
  },
  updated() {
      if (this.$route.path === "/") {
        this.heroFull = true;
        console.log("its at home");
      } else {
        this.heroFull = false;
        console.log("its not at home");
      }    
   }
 };

【讨论】:

  • 我试过了,但它根本没有更新 heroFull,为什么?
猜你喜欢
  • 1970-01-01
  • 2021-08-23
  • 2018-04-14
  • 2019-06-18
  • 2021-10-06
  • 1970-01-01
  • 2021-01-11
  • 2019-06-23
  • 2021-04-11
相关资源
最近更新 更多