官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 怀来县| 镇远县| 延边| 赤壁市| 西畴县| 三河市| 临猗县| 出国| 南靖县| 漳平市| 南雄市| 阳新县| 南平市| 西乡县| 佛冈县| 天长市| 太谷县| 溧水县| 兰州市| 滁州市| 印江| 仪陇县| 新蔡县| 专栏| 张家界市| 盐城市| 郴州市| 新河县| 梧州市| 嘉义市| 东海县| 钟祥市| 玉门市| 濉溪县| 沈丘县| 文昌市| 高邑县| 鹤岗市| 嵊泗县| 栖霞市| 郑州市|