1.0.7 • Published 5 years ago

vue2.x-context-menu v1.0.7

Weekly downloads
33
License
-
Repository
github
Last release
5 years ago

vue2.x-context-menu

vue2.x-context-menu在线示例

Install

npm install vue2.x-context-menu --save

//if you use yarn, you can

yarn add vue2.x-context-menu  

Usagehttps://nsne.github.io/vue2.x-context-menu/

Usage1 (Global Component)

import Vue from 'vue'
import contextmenu from 'vue2.x-context-menu';
import 'vue2.x-context-menu/dist/css/context-menu.css';

Vue.use(contextmenu);

If you register it as a global component, you can use it directly in the template tag of any component of your project. like this:

    <table style="width: 100%; margin-bottom: 20px;" class="ivu-table">
        <thead>
            <th>name</th>
            <th>sex</th>
            <th>age</th>
        </thead>
        <tbody>
            <tr @contextmenu="$refs.contextMenu.handleContextMenu($event, {name: 'aaa', sex: '男', age: 24})">
                <td>aaa</td>
                <td>男</td>
                <td>23</td>
            </tr>
            <tr @contextmenu="$refs.contextMenu.handleContextMenu($event, {name: 'bbb', sex: '女', age: '23'})">
                <td>bbb</td>
                <td>女</td>
                <td>23</td>
            </tr>
        </tbody>
    </table>
    <ContextMenu @handle-show="handleShow" ref="contextMenu">
        <div>
            <!-- 定义操作  -->
            <ContextMenuItem @click="handleSelect" label="哈哈哈1" value="哈哈哈1"><Icon type="checkmark" /></ContextMenuItem>
            <ContextMenuItem @click="handleSelect" label="哈哈哈2" value="哈哈哈2"><Icon type="wifi" /></ContextMenuItem>
        </div>
    </ContextMenu>

Usage2 (Local Component)

<template>
  <div>
        <div>
            <h2>result</h2>
            <h4>
                <label for="">menu:</label>
                <span>{{menu}}
                </span>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <label for="">operate:</label>
                <span> {{operate}}
                </span>
            </h4>
        </div>
        <br/>
        <table style="width: 100%; margin-bottom: 20px;">
            <thead>
                <th>name</th>
                <th>sex</th>
                <th>age</th>
            </thead>
            <tbody>
                <tr @contextmenu="$refs.contextMenu.handleContextMenu($event, {name: 'aaa', sex: '男', age: 24})">
                    <td>aaa</td>
                    <td>男</td>
                    <td>23</td>
                </tr>
                <tr @contextmenu="$refs.contextMenu.handleContextMenu($event, {name: 'bbb', sex: '女', age: '23'})">
                    <td>bbb</td>
                    <td>女</td>
                    <td>23</td>
                </tr>
            </tbody>
        </table>

        <div @contextmenu="$refs.contextMenu.handleContextMenu($event)" :style="{width: '1910px', height: '200px', backgroundColor: 'pink', marginBottom: '20px'}">哈哈哈</div>

        <div @contextmenu="$refs.contextMenu.handleContextMenu($event)" :style="{width: '1910px', height: '200px', backgroundColor: '#add8ad'}">哈哈哈</div>

        <ContextMenu @handle-show="handleShow" ref="contextMenu">
            <div>
                <!-- 定义操作  -->
                <ContextMenuItem @click="handleSelect" label="哈哈哈1" value="哈哈哈1"></ContextMenuItem>
                <ContextMenuItem @click="handleSelect" label="哈哈哈2" value="哈哈哈2"></ContextMenuItem>
            </div>
        </ContextMenu>

  </div>
</template>

<style>
tr {
    cursor: pointer;
}
</style>

<script>
//only for local registration, if you register it as a global component, You do not have to do that
import contextmenu from 'vue2.x-context-menu'
import 'vue2.x-context-menu/dist/css/context-menu.css'
const {ContextMenu, ContextMenuItem } = contextmenu

export default {
  data() {
      return {
          menu: '',
          operate: ''
      }
  },
  methods: {
      handleShow: function(val){
          this.menu = val;
          this.operate = '';
          console.log(this.menu);
      },
      handleSelect: function(val) {
          this.operate = val;
          console.log(this.operate);
      }
  }
}

</script>

API

As you can see, there are two components, ContextMenu and ContextMenuItem

下面就用中文啦,作为中国人,还是写点中文吧,再说英文写着也累

ContextMenu

props

属性说明类型默认值
width弹出窗口的宽度String或Number200

event

事件名说明返回值
handle-show鼠标右击时触发,返回点击的元素本身,即value值,此时可自己清除operate点击元素value

ContextMenuItem

props

属性说明类型默认值
label显示操作的标签String或Number
value点击菜单时的识别key,如删除操作可为deleteString或Number
disabled是否禁用Booleanfalse

event

事件名说明返回值
click点击某操作时触发,返回value属性
1.0.7

5 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago