0
0
Vueframework~20 mins

Mouse button modifiers in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Mouse Button Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when clicking with the middle mouse button?
Consider this Vue 3 component using mouse button modifiers:
<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>
ANothing happens because middle clicks are ignored by Vue.
BAn alert with 'Middle button clicked!' appears.
CThe alert appears only if the left mouse button is clicked.
DA syntax error occurs because @click.middle is invalid.
Attempts:
2 left
💡 Hint
Vue supports mouse button modifiers like .middle to detect specific mouse buttons.
📝 Syntax
intermediate
2: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?
A<div @click.right="handleRightClick">Right Click Me</div>
B<div @click.rightButton="handleRightClick">Right Click Me</div>
C<div @click.middle="handleRightClick">Right Click Me</div>
D<div @rightclick="handleRightClick">Right Click Me</div>
Attempts:
2 left
💡 Hint
Vue uses .right as a mouse button modifier on click events.
🔧 Debug
advanced
2:00remaining
Why does this middle click handler not work?
Look at this Vue 3 code snippet:
<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>
AThe .prevent modifier stops the event, so the handler never runs.
BThe .middle modifier only works on @mousedown, not @click.
CThe method name doSomething is reserved and cannot be used.
DThe browser's default action for middle click (opening a new tab) prevents the event from reaching Vue.
Attempts:
2 left
💡 Hint
Think about what middle click usually does in browsers.
state_output
advanced
2:00remaining
What is the value of count after clicking left and right buttons?
Given this Vue 3 component:
<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>
ACount: 0
BCount: 1
CCount: -1
DCount: NaN
Attempts:
2 left
💡 Hint
Think about how increment and decrement affect the count starting from zero.
🧠 Conceptual
expert
2: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?
A.left
B.right
C.back
D.middle
Attempts:
2 left
💡 Hint
Think about common mouse buttons and what Vue officially supports.