Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a reactive variable using Vue's Composition API.
Vue
import { ref } from 'vue'; const count = [1](0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reactive instead of ref for primitive values
Using computed or watch incorrectly here
✗ Incorrect
Use ref to create a reactive primitive value like a number.
2fill in blank
mediumComplete the code to watch the reactive variable and log its new value.
Vue
import { ref, watch } from 'vue'; const count = ref(0); watch(count, (newVal) => { console.log([1]); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Logging the reactive variable instead of the new value parameter
Using count.value inside the watcher callback
✗ Incorrect
The watcher callback receives the new value as the first argument, here named newVal.
3fill in blank
hardFix the error in the code to correctly update a reactive object property.
Vue
import { reactive } from 'vue'; const state = reactive({ count: 0 }); function increment() { state.[1] += 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .value on reactive object properties
Trying to update the whole reactive object instead of a property
✗ Incorrect
When using reactive, access properties directly without .value.
4fill in blank
hardFill both blanks to create a computed property that doubles the count.
Vue
import { ref, computed } from 'vue'; const count = ref(5); const double = computed(() => count[1][2]2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting
.value to access the refUsing addition or other wrong operators
✗ Incorrect
Use .value to access the ref value and * to multiply by 2.
5fill in blank
hardFill all three blanks to create a reactive object with a nested property and update it.
Vue
import { reactive } from 'vue'; const state = reactive({ user: { name: [1] } }); function updateName(newName) { state.user.[2] = [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes incorrectly around property names
Confusing the property name and value
✗ Incorrect
Initialize name with 'Alice', then update state.user.name to newName.