Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a reactive object in Vue.
Vue
const state = reactive({ count: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using null or undefined as initial count causes unexpected behavior.
✗ Incorrect
We start the count at 0 to track changes reactively.
2fill in blank
mediumComplete the code to watch a reactive property in Vue.
Vue
watch(() => state.count, (newVal, oldVal) => { console.log([1]) }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Logging oldVal shows the previous value, not the current one.
✗ Incorrect
We log the new value whenever the count changes.
3fill in blank
hardFix the error in the code to update a nested reactive property correctly.
Vue
state.user.name = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string literals causes runtime errors.
✗ Incorrect
Strings must be wrapped in quotes to assign properly.
4fill in blank
hardFill both blanks to create a computed property that doubles a reactive count.
Vue
const doubleCount = computed(() => state.count [1] 2 [2] 0 )
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * changes the meaning.
✗ Incorrect
We multiply count by 2, then add 0 (which is optional but here for syntax).
5fill in blank
hardFill all three blanks to create a reactive object with a nested reactive array and update it.
Vue
const state = reactive({ items: [1] })
state.items.push([2])
console.log(state.items[[3]]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using {} instead of [] for array initialization causes errors.
✗ Incorrect
We start with an empty array, push a string, then log the first item at index 0.