Challenge - 5 Problems
Vue Memo Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does
v-memo affect component rendering?Consider a Vue component using
v-memo with a dependency array. What happens when a reactive property outside the dependency array changes?Vue
<template> <div v-memo="[count]">Count is: {{ count }}</div> <button @click="increment">Increment</button> <button @click="changeName">Change Name</button> </template> <script setup> import { ref } from 'vue' const count = ref(0) const name = ref('Vue') function increment() { count.value++ } function changeName() { name.value = name.value === 'Vue' ? 'JS' : 'Vue' } </script>
Attempts:
2 left
💡 Hint
Think about what
v-memo watches to decide re-rendering.✗ Incorrect
v-memo tells Vue to re-render the element only if the values in its dependency array change. Since only count is in the array, changes to name do not trigger re-render.
📝 Syntax
intermediate1:30remaining
Identify the correct
v-memo syntax for multiple dependenciesWhich of the following is the correct way to use
v-memo with two reactive dependencies foo and bar?Attempts:
2 left
💡 Hint
Remember that
v-memo expects an array of dependencies.✗ Incorrect
The correct syntax uses an array to list dependencies: [foo, bar]. Other options are invalid JavaScript expressions or do not represent arrays.
🔧 Debug
advanced2:30remaining
Why does this
v-memo not prevent re-rendering?Given this code snippet, why does the element re-render even when
count does not change?
<template>
<div v-memo="[count]">Count: {{ count }}</div>
<button @click="increment">Increment</button>
</template>
<script setup>
import { ref } from 'vue'
const count = ref(0)
function increment() {
count.value++
}
</script>
Assume the button is clicked but count is not incremented.Attempts:
2 left
💡 Hint
Think about what triggers re-render when
v-memo is used.✗ Incorrect
v-memo prevents re-render if dependencies do not change. If the element re-renders without count changing, another reactive source or parent re-render caused it.
❓ state_output
advanced2:00remaining
What is the output after toggling a dependency in
v-memo?Given this Vue component:
<template>
<div v-memo="[show]">Visible: {{ show }}</div>
<button @click="toggleShow">Toggle</button>
</template>
<script setup>
import { ref } from 'vue'
const show = ref(true)
function toggleShow() {
show.value = !show.value
}
</script>
What will the div display after clicking the button twice?Attempts:
2 left
💡 Hint
Each toggle changes the
show value, which is a dependency of v-memo.✗ Incorrect
Since show is in the v-memo dependency array, toggling it causes the div to re-render and update its displayed value accordingly.
🧠 Conceptual
expert3:00remaining
Why use
v-memo for conditional memoization in Vue?Which of the following best explains the main benefit of using
v-memo in Vue components?Attempts:
2 left
💡 Hint
Think about how memoization helps with rendering efficiency.
✗ Incorrect
v-memo helps Vue skip rendering parts of the template when dependencies are unchanged, which can reduce unnecessary work and improve app speed.