0

假设我有一个正常的过渡,效果很好(遵循 vue 文档)。但我想在那个里面有另一个过渡。

例如,一个元素滑入,但其中的文本同时淡入

我无法让内部孩子过渡到动画。不会被解雇吧?我试过“出现”也认为节点是新的。

几乎没有这方面的信息。

<div id="demo">
  <transition name="slide">
    <div v-if="show">
      <transition name="slide-fade">
        <p>hello</p>
      </transition>
    </div>
  </transition>
</div>

过渡效果

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}

.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateX(10px);
  opacity: 0;
}
4

1 回答 1

0

您似乎没有为slide组件添加过渡 CSS。以下应该有效:

const vm = new Vue({
  el: '#demo',
  data() {
    return {
      show: true
    }
  }
})
.slide-fade-enter-active,
.slide-fade-leave-active {
  transition: opacity 0.5s;
}

.slide-fade-enter,
.slide-fade-leave-to {
  opacity: 0;
}

.slide-enter-active {
  transition: all 0.3s ease;
}

.slide-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-enter,
.slide-leave-to {
  transform: translateX(10px);
  opacity: 0;
}

/* Some styling to make them noticeable */
.parent {
  background-color: lightgray;
  padding: 2px;
}

.child {
  background-color: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="demo">
  <transition name="slide">
    <div v-if="show" class="parent">
      <transition name="slide-fade">
        <p class="child">hello</p>
      </transition>
    </div>
  </transition>

  <button @click="show = !show">Toggle</button>
</div>

于 2019-01-04T02:46:22.857 回答