Count starts at 0 and increments by 1 each time increment() is called.
Step 2: Trace component setup execution
Increment is called twice, so count.value becomes 2, then logged.
Final Answer:
2 -> Option A
Quick Check:
Two increments = count 2 [OK]
Hint: Count increments twice, so value is 2 [OK]
Common Mistakes:
Forgetting to call increment()
Confusing ref with plain variable
Expecting count to be 0 without increments
4. Identify the error in this composable usage:
import { ref } from 'vue';
export function useData() {
const data = ref(null);
fetch('/api').then(res => res.json()).then(json => data = json);
return { data };
}
medium
A. Using ref instead of reactive
B. Missing await keyword before fetch
C. Reassigning the ref variable instead of its value
D. Not returning the data variable
Solution
Step 1: Check how ref is updated
Ref variables must update their .value, not be reassigned.
Step 2: Identify the mistake in the fetch callback
The code assigns data = json instead of data.value = json.
Final Answer:
Reassigning the ref variable instead of its value -> Option C
Quick Check:
Update ref.value, not ref itself [OK]
Hint: Update ref.value, not the ref variable [OK]
Common Mistakes:
Assigning directly to ref variable
Forgetting to handle async properly
Confusing reactive with ref usage
5. You want to share a composable that tracks a user's online status across multiple components. Which approach ensures each component has its own independent reactive state?
hard
A. Export a single reactive object and import it directly in all components
B. Export a function that returns new refs each call, then import and call it in each component
C. Define reactive state inside a global variable outside the composable
D. Use a Vuex store instead of composables for reactive state
Solution
Step 1: Understand independent reactive state per component
Each component needs its own fresh reactive refs to avoid shared state.
Step 2: Identify correct composable pattern
Exporting a function that returns new refs each call creates isolated state per component.
Final Answer:
Export a function that returns new refs each call, then import and call it in each component -> Option B
Quick Check:
Function returns fresh state per call [OK]
Hint: Return new refs inside function for isolated state [OK]
Common Mistakes:
Sharing a single reactive object causing shared state
Using global variables outside composables
Confusing Vuex with composables for local state
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.