# Contextmenu

# Disable Contextmenu

You can disable the contextmenu by configuring :contextmenu="false"

Example:

<router-tab :contextmenu="false" />
1

# Custom Contextmenu

Configure contextmenu through an array to customize the contextmenu

Example:

Template

<router-tab
  :class="{ 'is-fullscreen': fullscreen }"
  :contextmenu="contextmenu"
/>
1
2
3
4

Javascript

// full screen mixin
import fullscreen from '../../mixins/fullscreen'

export default {
  mixins: [fullscreen],

  computed: {
    contextmenu() {
      return [
        // Built-in menu
        'refresh',

        // Extend built-in menu: add icon
        {
          id: 'close',
          icon: 'rt-icon-close'
        },

        // Extend built-in menu: custom handler
        {
          id: 'closeOthers',
          handler({ $menu }) {
            $menu.closeMulti($menu.others)
            alert('Close other tabs')
          }
        },

        // custom menu
        {
          id: 'custom',
          title: 'Custom Action',
          tips: 'This is a custom action',
          icon: 'rt-icon-doc',
          class: 'custom-action',
          // Whether to display or not, default display
          visible(context) {
            return context.$tabs.items.length < 3
          },
          // Whether it is enabled or not, it will be enabled by default
          enable(context) {
            return !(context.data.index % 2)
          },
          // Click to trigger
          handler(context) {
            console.log(context)
            alert(
              'This is a custom operation, please open the console to view the output parameters'
            )
          }
        },

        // Menu with status: fullscreen
        {
          id: 'fullscreen',
          title: () => (this.fullscreen ? 'Exit Full Screen' : 'Full Screen'),
          icon: () =>
            this.fullscreen ? 'rt-icon-fullscreen-exit' : 'rt-icon-fullscreen',
          // Click to trigger
          handler: () =>
            setTimeout(() => {
              this.fullscreen = !this.fullscreen
            }, 300)
        }
      ]
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Last updated: 3/26/2021, 3:19:02 PM