- Vue.js 2 Web Development Projects
- Guillaume Chau
- 221字
- 2021-07-02 22:34:35
Key attribute
For now, if you try the animation in the browser, it should only work in two cases:
- When you don't have any overlay displayed, and you set one
- When you have an overlay shown and you set activeOverlay to null to hide it
If you switch between the overlays, the animation will not work. This is because of the way Vue updates the DOM; as we saw earlier in the The key special attribute section, it will reuse DOM elements as much as possible to optimize performance. In that case, we will need to use the key special attribute to give Vue a hint that we would like to treat the different overlays as separate elements. So, when we transition from one overlay to the other, both will be present in the DOM, and the animations can be played.
Let's add the key to our overlay component so that Vue will treat it as multiple separate elements when we change the activeOverlay value:
<transition name="zoom">
<overlay v-if="activeOverlay" :key="activeOverlay">
<component :is="'overlay-content-' + activeOverlay" :player="currentPlayer" :opponent="currentOpponent" :players="players" />
</overlay>
</transition>
Now, if we set activeOverlay to 'player-turn', the overlay will have a key of 'player-turn'. Then, if we set activeOverlay to 'last-play', an entirely new overlay will be created with a key of 'last-play', and we can animate the transition between the two. You can try this in the browser by setting different values to state.activeOverlay.
- 密碼學(xué)原理與Java實現(xiàn)
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- Microsoft Dynamics 365 Extensions Cookbook
- Learning RxJava
- Selenium Design Patterns and Best Practices
- 精通網(wǎng)絡(luò)視頻核心開發(fā)技術(shù)
- Linux C編程:一站式學(xué)習(xí)
- Spring Boot+MVC實戰(zhàn)指南
- PHP 7從零基礎(chǔ)到項目實戰(zhàn)
- Hadoop 2.X HDFS源碼剖析
- Python數(shù)據(jù)科學(xué)實踐指南
- Data Manipulation with R(Second Edition)
- UI動效設(shè)計從入門到精通
- C++ Windows Programming
- Continuous Integration,Delivery,and Deployment