如何在另一个转换“内部”使用Vue JS转换?

时间:2019-01-03 21:16:37

标签: vue.js transition vuejs-transition

说我有一个正常的过渡,效果很好(遵循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;
}

1 个答案:

答案 0 :(得分: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>