When switching from 'CompA' to 'CompB', the state of 'CompA' is lost. Why?
medium
A. Because 'CompB' is excluded, switching to it destroys cached components including 'CompA'
B. Because 'CompB' is excluded, only 'CompB' is not cached; 'CompA' should keep state
C. Because 'CompB' is excluded, keep-alive disables caching for all components
D. Because exclude disables keep-alive entirely
Solution
Step 1: Understand exclude behavior
The exclude attribute prevents caching only for 'CompB'. Other components like 'CompA' remain cached.
Step 2: Analyze why 'CompA' state is lost
If 'CompA' state is lost, likely the component is unmounted or recreated outside keep-alive scope, not due to exclude.
Final Answer:
Because 'CompB' is excluded, only 'CompB' is not cached; 'CompA' should keep state -> Option B
Quick Check:
Exclude only skips caching excluded components [OK]
Hint: Exclude skips caching only for listed components [OK]
Common Mistakes:
Thinking exclude disables caching for all components
Assuming exclude destroys other cached components
Confusing exclude with disabling keep-alive
5. You have two expensive components, CompX and CompY. You want to cache CompX but not CompY. Which is the best way to use <keep-alive> to achieve this?
hard
A.
B.
C.
D.
Solution
Step 1: Identify caching goal
You want to cache only CompX, not CompY.
Step 2: Use include to cache specific components
Setting include="CompX" caches only CompX. CompY won't be cached.
Step 3: Check other options
Exclude CompX caches everything except CompX (wrong). Include CompY caches only CompY (wrong). No filters caches all (wrong).
Final Answer:
<keep-alive include="CompX"><component :is="currentComp" /></keep-alive> -> Option D
Quick Check:
Include caches only listed components [OK]
Hint: Use include to cache only desired components [OK]
Common Mistakes:
Using exclude to cache only one component
Including the wrong component name
Not using include or exclude and caching all
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.