v-if和v-else的Vue过渡不起作用

时间:2019-01-03 19:18:32

标签: animation vue.js transition

我无法使用转场或转场组添加动画。我有代码:

    <transition mode="out-in" enter-active-class="animated zoomIn" leave-active-class="animated zoomOut">
        <div key=1 v-if="$route.name !== null">
            <router-view></router-view>
        </div>
        <div v-else key=2>
            <p>First text</p>
            <p>Second text</p>
        </div>
    </transition>

transtitiontransition-group的更改无济于事。过渡应围绕:

<div v-if="$route.name !== null">
   <router-view></router-view>
</div>

<p>First tex</p>
<p>Second text</p>

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。我使用了transition两次。我不知道是否应该这样做,但是现在可以了。

    <transition mode="out-in" enter-active-class="animated zoomIn" leave-active-class="animated zoomOut">
        <div key="save" v-if="$route.name !== null">
             <transition mode="out-in" enter-active-class="animated zoomIn" leave-active-class="animated zoomOut">
            <router-view></router-view>
            </transition>
        </div>
        <div v-else key="edit">
           <p>First tex</p>
           <p>Second text</p>
        </div>
    </transition>