2016-10-28 90 views

回答

6
工作

在具有相同標籤名稱的元素之間切換時,必須告訴Vue它們是不同的元素,方法是爲它們提供唯一的屬性。否則,Vue的編譯器只會替換元素的內容以提高效率。即使在技術上沒有必要,但總是在組件內鍵入多個項目被認爲是很好的做法。

另外的過渡必須在出-in模式

HTML:

<div id="test"> 
    <transition name="fade" mode="out-in"> 
    <p :key="foo[counter]"> 
     {{ foo[counter] }} 
    </p> 
    </transition> 
    <button @click="counter++"> 
    next 
    </button> 
    <button @click="counter--"> 
    before 
    </button> 
</div> 

JS:

new Vue({ 
el:'#test', 
data:{ 
    counter:0, 
    show:true, 
    foo:['a','b','c'] 
} 
}) 

段: https://jsfiddle.net/L4r64yxk/

+0

謝謝!那是不行的! –

+0

哇!這應該更經常地澄清!我堅持了幾個小時 –