Challenge - 5 Problems
Vue Reactivity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What triggers a Vue component to re-render?
In Vue 3's Composition API, which action causes a component to automatically re-render?
Vue
import { ref } from 'vue'; const count = ref(0); function increment() { count.value++; } // When does the component update its display?
Attempts:
2 left
💡 Hint
Think about what Vue watches to know when to update the UI.
✗ Incorrect
Vue tracks reactive properties like ref and reactive objects. When their values change, Vue knows to re-render the component automatically.
🧠 Conceptual
intermediate2:00remaining
How does Vue know which properties to track?
Vue uses a special system to track dependencies. Which best describes how Vue tracks reactive properties?
Attempts:
2 left
💡 Hint
Think about how Vue can know when you read or write a property.
✗ Incorrect
Vue uses JavaScript proxies or getters/setters to intercept property access and changes, so it can track dependencies automatically.
🔧 Debug
advanced2:00remaining
Why does this Vue reactive property not trigger updates?
Consider this Vue 3 code snippet. Why does changing
state.count not update the template?Vue
<script setup> import { reactive } from 'vue'; const state = reactive({ count: 0 }); function increment() { state.count = state.count + 1; } </script> <template> <button @click="increment">Increment</button> <p>{{ state.count }}</p> </template>
Attempts:
2 left
💡 Hint
Check how reactive objects and templates work together in Vue 3.
✗ Incorrect
Reactive objects created with reactive() are tracked by Vue, and changes to their properties trigger updates. This code works correctly.
📝 Syntax
advanced2:00remaining
Which code correctly creates a reactive computed property in Vue 3?
Select the code snippet that correctly defines a computed property that doubles a reactive count.
Attempts:
2 left
💡 Hint
Remember how to access the value inside a ref.
✗ Incorrect
Computed properties use a function returning a value. When using ref, you must access the value with .value.
❓ state_output
expert2:00remaining
What is the output after these Vue reactive updates?
Given this Vue 3 code, what is the final value of
message.value after calling update()?Vue
import { ref, watch } from 'vue'; const count = ref(0); const message = ref('Start'); watch(count, (newVal) => { message.value = `Count is ${newVal}`; }); function update() { count.value = 1; count.value = 2; } update();
Attempts:
2 left
💡 Hint
Think about how Vue batches reactive updates and when watchers run.
✗ Incorrect
Vue batches reactive updates in the same tick. The watcher runs after all changes, so message.value reflects the last count value, 2.