Why might the handleRight method not run when right-clicking the div?
medium
A. Because .prevent modifier stops the event from firing.
B. Because @click.right is invalid syntax.
C. Because handleRight is not defined.
D. Because the browser's context menu blocks the event.
Solution
Step 1: Understand the effect of .prevent modifier
The .prevent modifier calls event.preventDefault() to stop default browser actions like navigation or form submission, but does not stop event handlers from running.
Step 2: Consider browser default behavior on right-click
Right-click usually opens the context menu, which can interfere with event handling unless prevented explicitly.
Step 3: Identify why handleRight might not run
If the context menu appears, it may block the event or user interaction, so the handler might not seem to run.
Final Answer:
Because the browser's context menu blocks the event. -> Option D
Quick Check:
Right-click triggers context menu unless prevented [OK]
Hint: Right-click triggers context menu unless prevented [OK]
Common Mistakes:
Thinking .prevent stops event handler
Assuming @click.right is invalid
Ignoring browser default context menu
5. You want to create a Vue component that only reacts to left and middle mouse clicks but ignores right clicks. Which is the best way to write the event listeners?
hard
A. <div @click.left.middle="onLeftMiddle">Click</div>
B. <div @click.left="onLeft" @click.middle="onMiddle">Click</div>
C. <div @click.right="onRight">Click</div>
D. <div @click="onAnyClick">Click</div>
Solution
Step 1: Identify required mouse buttons
The component should respond only to left and middle clicks, ignoring right clicks.
Step 2: Check each option's event listeners
<div @click.left="onLeft" @click.middle="onMiddle">Click</div> uses separate listeners for .left and .middle, correctly handling both buttons.
Step 3: Evaluate other options
<div @click.left.middle="onLeftMiddle">Click</div> uses an invalid combined modifier .left.middle. <div @click.right="onRight">Click</div> listens only to right clicks, which should be ignored. <div @click="onAnyClick">Click</div> listens to all clicks, including right clicks.
Final Answer:
<div @click.left="onLeft" @click.middle="onMiddle">Click</div> -> Option B
Quick Check:
Separate .left and .middle listeners handle clicks correctly [OK]
Hint: Use separate @click.left and @click.middle listeners [OK]
Common Mistakes:
Trying to combine .left and .middle in one modifier
Listening to right clicks when not needed
Using generic @click without filtering buttons
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.