0
0
Vueframework~20 mins

Transition modes (in-out, out-in) in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when using mode="in-out" in Vue transitions?

Consider a Vue component that toggles between two elements with a <transition> wrapper using mode="in-out". What is the behavior of the entering and leaving elements?

Vue
<template>
  <transition name="fade" mode="in-out">
    <component :is="currentComponent" :key="currentComponent" />
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const currentComponent = ref('CompA')
// toggling logic omitted
</script>
ABoth elements enter and leave simultaneously without waiting for each other.
BThe old element leaves first, then the new element enters after the leave transition finishes.
CThe new element enters first, then the old element leaves after the enter transition finishes.
DThe transition mode is ignored and elements switch instantly without animation.
Attempts:
2 left
💡 Hint

Think about which element Vue waits for before starting the other transition.

component_behavior
intermediate
2:00remaining
How does mode="out-in" affect Vue transition timing?

Given a Vue transition with mode="out-in", what is the sequence of the leaving and entering elements?

Vue
<template>
  <transition name="slide" mode="out-in">
    <component :is="currentView" :key="currentView" />
  </transition>
</template>
AThe transition mode causes a flicker and no animation occurs.
BThe new element enters immediately while the old element is still leaving.
CBoth elements transition simultaneously without waiting.
DThe old element leaves first, then the new element enters after the leave transition finishes.
Attempts:
2 left
💡 Hint

Consider which element Vue waits to finish before starting the other.

📝 Syntax
advanced
2:00remaining
Which Vue transition mode value causes this error?

What error occurs if you set mode="inout" (without the dash) on a Vue <transition> component?

Vue
<template>
  <transition name="fade" mode="inout">
    <div v-if="show">Content</div>
  </transition>
</template>
AVue ignores the mode and transitions run simultaneously without error.
BVue throws a warning and defaults to no mode, running transitions simultaneously.
CVue throws a runtime error and the component fails to render.
DVue treats it as <code>in-out</code> mode automatically.
Attempts:
2 left
💡 Hint

Check Vue's behavior on invalid mode values.

state_output
advanced
2:00remaining
What is the visible output order with mode="in-out" when toggling components?

Given a Vue app toggling between CompA and CompB inside a <transition mode="in-out">, which component is visible first during the transition?

Vue
<template>
  <button @click="toggle">Toggle</button>
  <transition name="fade" mode="in-out">
    <component :is="current" :key="current" />
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const current = ref('CompA')
function toggle() {
  current.value = current.value === 'CompA' ? 'CompB' : 'CompA'
}
</script>
ACompB appears first, then CompA fades out after CompB finishes entering.
BCompA fades out first, then CompB appears after CompA finishes leaving.
CBoth components appear and disappear simultaneously.
DNo transition occurs; components switch instantly.
Attempts:
2 left
💡 Hint

Recall the in-out mode behavior for entering and leaving elements.

🔧 Debug
expert
3:00remaining
Why does the out-in transition cause a flicker in this Vue app?

In a Vue app using <transition mode="out-in"> to switch views, users notice a flicker (blank space) between transitions. What is the most likely cause?

Vue
<template>
  <transition name="fade" mode="out-in">
    <component :is="currentView" :key="currentView" />
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const currentView = ref('ViewA')
// toggling logic omitted
</script>
AThe leaving element is removed before the entering element is mounted, causing a brief empty space.
BVue does not support <code>out-in</code> mode, so flicker is expected.
CCSS transition durations are mismatched causing flicker during overlap.
DThe entering element is mounted too early, overlapping the leaving element causing flicker.
Attempts:
2 left
💡 Hint

Think about the sequence of element removal and insertion in out-in mode.