0.2.0 • Published 5 years ago

iview-contextmenu v0.2.0

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

iview-contextmenu

version NPM download license

A contextmenu component depend on iview-dropdown component.

Demo

demo

Engilsh | 中文

Install

Using npm:

npm install iview-contextmenu

Usage

main.js:

import Vue from 'vue'
import iView from 'iview'
import Contextmenu from 'iview-contextmenu'

import 'iview/dist/styles/iview.css'
import 'iview-contextmenu/dist/iview-contextmenu.css'

Vue.use(iView)
Vue.use(Contextmenu)

App.vue:

<template>
  <div
    id="app"
    @contextmenu.prevent="preventContextmenu"
  >
    <!-- It will respond to document contextmenu event when no set trigger = 'custom' -->
    <Contextmenu
      :menu-data="menuData"
      @on-select="handleSelect"
      @on-cancel="handleCancel"
    ></Contextmenu>
  </div>
</template>

<script>
export default {
  name: 'App',
  data () {
    return {
      menuData: [
        {
          title: 'Menu1',
          name: 'menu1'
        },
        {
          title: 'Menu2',
          name: 'menu2',
          shortcut: 'Ctrl+J'
        },
        {
          title: 'Menu3',
          name: 'menu3',
          divided: true,
          disabled: true
        }
      ]
    }
  },
  methods: {
    handleSelect (name) {
      console.log(`select contextmenu: ${name}`)
    },
    handleCancel () {
      console.log('cancel contextmenu')
    },
    preventContextmenu () {
      return false
    }
  }
}
</script>

<style>
* {
  box-sizing: border-box;
}
html, body {
  height: 100%;
}
body {
  overflow: hidden;
}
#app {
  height: 100%;
}
</style>

Props

PropertyDesciptionTypeDefault
menu-dataAn Array that generates the contextmenu.Array-
triggerSet to 'custom' to control visible manually.String''
visibleControl the display of Contextmenu manually, used when trigger = 'custom'.Booleanfalse

Events

Event NameDescriptionReturn Value
on-selectEmit when clicking the contextmenu item, the return value will be 'parentName-childName' when clicking the child menu.ContextmenuItem's prefixName
on-cancelTriggered when click the outside body.-

Params

KeyDescriptionTypeDefault
titleItem's title.String-
nameUsed to tag the item.String-
visibleUsed to hidden the item.Booleantrue
dividedShow spilt line.Booleanfalse
desabledUsed to disable the item.Booleanfalse
iconRight icon Type, it will be ignored when item has children.String-
shortcutRight text content, it wiil be ignored when right icon is set or item has children.String-
childrenThe son itemArray-
prefixPrefix the children name when to select item's children, default used name value when no setString-

License

MIT

Copyright (c) 2019-present, iview-contextmenu