Challenge - 5 Problems
Mouse Button Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when clicking with the middle mouse button?
Consider this Vue 3 component using mouse button modifiers:
What will happen when the user clicks the button with the middle mouse button?
<template>
<button @click.middle="middleClick">Click me</button>
</template>
<script setup>
function middleClick() {
alert('Middle button clicked!')
}
</script>What will happen when the user clicks the button with the middle mouse button?
Vue
<template> <button @click.middle="middleClick">Click me</button> </template> <script setup> function middleClick() { alert('Middle button clicked!') } </script>
Attempts:
2 left
💡 Hint
Vue supports mouse button modifiers like .middle to detect specific mouse buttons.
✗ Incorrect
The .middle modifier listens for clicks from the middle mouse button. So clicking with the middle button triggers the middleClick function and shows the alert.
📝 Syntax
intermediate2:00remaining
Which option correctly uses the right mouse button modifier?
You want to run a method only when the right mouse button is clicked on a div. Which Vue syntax is correct?
Attempts:
2 left
💡 Hint
Vue uses .right as a mouse button modifier on click events.
✗ Incorrect
The correct modifier for the right mouse button on click events is .right. Other options are invalid or refer to different buttons.
🔧 Debug
advanced2:00remaining
Why does this middle click handler not work?
Look at this Vue 3 code snippet:
The doSomething method never runs when clicking the middle mouse button. Why?
<button @click.middle.prevent="doSomething">Click</button>
The doSomething method never runs when clicking the middle mouse button. Why?
Vue
<button @click.middle.prevent="doSomething">Click</button>Attempts:
2 left
💡 Hint
Think about what middle click usually does in browsers.
✗ Incorrect
Middle clicking a link or button often triggers the browser to open a new tab. This default action can prevent Vue's click event handler from running unless you prevent the default behavior.
❓ state_output
advanced2:00remaining
What is the value of count after clicking left and right buttons?
Given this Vue 3 component:
If the user clicks the button once with the left mouse button, then once with the right mouse button, what is the displayed count?
<template>
<button @click.left="increment" @click.right="decrement">Click</button>
<p>Count: {{ count }}</p>
</template>
<script setup>
import { ref } from 'vue'
const count = ref(0)
function increment() { count.value++ }
function decrement() { count.value-- }
</script>If the user clicks the button once with the left mouse button, then once with the right mouse button, what is the displayed count?
Vue
<template> <button @click.left="increment" @click.right="decrement">Click</button> <p>Count: {{ count }}</p> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value++ } function decrement() { count.value-- } </script>
Attempts:
2 left
💡 Hint
Think about how increment and decrement affect the count starting from zero.
✗ Incorrect
Clicking left increments count from 0 to 1. Clicking right decrements count from 1 back to 0. So the final count is 0.
🧠 Conceptual
expert2:00remaining
Which mouse button modifier does NOT exist in Vue 3?
Vue 3 supports mouse button modifiers for click events like .left, .right, and .middle. Which of these is NOT a valid Vue mouse button modifier?
Attempts:
2 left
💡 Hint
Think about common mouse buttons and what Vue officially supports.
✗ Incorrect
Vue 3 officially supports .left, .right, and .middle modifiers for mouse buttons. There is no .back modifier for mouse buttons in Vue.