0
0
Vueframework~20 mins

How Vue tracks dependencies automatically - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Reactivity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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?
AWhen a reactive property like count.value changes
BWhen any function inside setup() is called
COnly when the component is manually refreshed
DWhen a non-reactive variable changes
Attempts:
2 left
💡 Hint
Think about what Vue watches to know when to update the UI.
🧠 Conceptual
intermediate
2: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?
AVue wraps reactive properties with getters and setters to detect access and changes
BVue scans the entire component code for variable names
CVue requires manual registration of each reactive property
DVue uses global event listeners to detect changes
Attempts:
2 left
💡 Hint
Think about how Vue can know when you read or write a property.
🔧 Debug
advanced
2: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>
AThe reactive object is correct; the problem is elsewhere
BThe template does not track reactive properties inside reactive objects
CThe code is correct and will update the template as expected
DThe reactive object was not created properly; it should use ref instead
Attempts:
2 left
💡 Hint
Check how reactive objects and templates work together in Vue 3.
📝 Syntax
advanced
2: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.
Aconst doubleCount = computed(() => count.value + 2);
Bconst doubleCount = computed(() => count.value * 2);
Cconst doubleCount = computed(count * 2);
Dconst doubleCount = computed(() => count * 2);
Attempts:
2 left
💡 Hint
Remember how to access the value inside a ref.
state_output
expert
2: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();
A"Count is 1"
B"Start"
CAn error is thrown
D"Count is 2"
Attempts:
2 left
💡 Hint
Think about how Vue batches reactive updates and when watchers run.