Skip to content

Listen for Right Mouse Click ​

Used to add right mouse click event listeners to components.

Installation ​

To install all directives, refer to Directives Installation.

Import and Registration ​

vue
<script>
import { HvRightClickDirective } from 'havue'
// or
import { HvRightClickDirective } from '@havue/directives'
</script>

Registration:

  • Full havue: Using app.use(havue) auto-registers the directive; use v-right-click directly.
  • @havue/directives only: Register manually: app.directive('right-click', HvRightClickDirective).

Directive Arguments ​

ArgumentDescription
upFired when right mouse button is released
downFired when right mouse button is pressed
contextmenuFired when the browser context menu event fires

Modifiers ​

ModifierDescription
.stopCalls event.stopPropagation()
.preventCalls event.preventDefault() (e.g. prevent context menu)
.captureAdd listener in capture phase

Binding Value ​

Expected type: Function, callback receives (e?: MouseEvent).

Examples ​

vue
<!-- Right button release event -->
<button v-right-click:up="doThis"></button>

<!-- Right button press event -->
<button v-right-click:down="doThis"></button>

<!-- Context menu event -->
<button v-right-click:contextmenu="doThis"></button>

<!-- Prevent context menu -->
<button v-right-click:contextmenu.prevent></button>

<!-- Listen for right button press and prevent default behavior -->
<button v-right-click:down.prevent="doThis"></button>

<!-- Listen for right button press and stop event propagation -->
<button v-right-click:down.stop="doThis"></button>
阻止右键菜单(Prevents right-clicking contextmenu)
Click to view code
vue
// #region code
<template>
  <div class="box" v-right-click:contextmenu.prevent>阻止右键菜单(Prevents right-clicking contextmenu)</div>
</template>

<script setup lang="ts">
import { HvRightClickDirective as vRightClick } from '@havue/directives'
</script>

<style lang="scss" scoped>
.box {
  width: 200px;
  height: 100px;
  color: black;
  text-align: center;
  background-color: aquamarine;
}
</style>
// #endregion code