GithubHelp home page GithubHelp logo

boenfu / vue-easycm Goto Github PK

View Code? Open in Web Editor NEW
52.0 2.0 7.0 52 KB

:cookie: Simplify Vue context menu component

Home Page: http://boenfu.github.io/vue-easycm/

HTML 30.45% Vue 55.23% JavaScript 14.32%
vue context-menu contextmenu

vue-easycm's Introduction

vue-easycm

一个简单好用的 VUE 环境菜单 (Context Menu)

更多demo: http://boenfu.github.io/vue-easycm/

http://boho.image.alimmdn.com/github/easycmdemo.gif?t=1524493555136

  • 配置简单 自定义程度高

  • 多种引用方式

  • 最高三层菜单

  • 可添加字体图标

  • 边界检测

Install

npm install vue-easycm --save

Use

  1.Import 导入

ES6

// 方法1.通过use挂载
import VueEasyCm from 'vue-easycm'
Vue.use(VueEasyCm)


//  方法2.通过require 导入
var VueEasyCm = require('VueEasyCm')



// 方法3.或者直接导入js文件
<script src="./dist/vue-easycm.js"></script>

  2.Basic Usage 基础用法

  1. 在需要触发 环境菜单 的容器标签上加上(固定写法)

    例:

    <div @contextmenu="$easycm($event,$root)"></div>

  2. 任意位置导入组件(选项数组必传,格式见配置项)

    例:

    <easy-cm :list=""></easy-cm>

3.Options 配置项

选项名 是否必须 默认值 介绍
:list true 选项数组
:tag false 配置多个时的标记
@ecmcb false 返回触发元素序号
:underline false false 是否开启下划线
:arrow false false 是否开启箭头
:border false true 是否开启边界检测
:itemWidth false 140 列表项宽度
:itemHeight false 36 列表项高度
:itemSize false 14 列表项字体大小
:offset false { x: 6, y: 2 } 显示点偏移量
:borderWidth false 6 边界距离

详细介绍:

  1. 数组格式如下

    [{
          text: 'Play Now',
          icon: 'iconfont icon-bofang',  //选填 字体图标 class
          children: [] //选填
    }]

    *嵌套的子项格式一致

  2. tag --> 标记

    需要配置多个菜单时添加 tag , 类似取个 id

    此时 @contextmenu="$easycm($event,$root,[tag])" 需要加上 tag 的值

    如:

    <div @contextmenu="$easycm($event,$root,1)">
        <p @contextmenu="$easycm($event,$root,2)"></p>
    </div>
    <easy-cm :tag="1"></easy-cm>
    <easy-cm :tag="2"></easy-cm>

    这个时候 在 p 元素上会触发 tag 为 2 的菜单

    div 的其他部分会触发 tag 为 1 的菜单

  3. ecmcb --> 回调函数

    解释:返回触发的序号数组,便于触发相应逻辑

    如:

    ​ [0] 代表第一层的第一项

    ​ [0,1] 代表第一层的第一项的第二个子项

    详见 demo code

  4. 边界检测 见 demo gif

  5. offset --> 显示点偏移量

    解释: 菜单显示位置的左上角离鼠标的距离

    如: {x:10,y:10}

    *数值参数均无需带单位

自定义样式

编写 预置的空 easy-cm-ul 样式类来修改样式

// 代码结构
<ul class="easy-cm-ul">
    <li>
      <div></div>
      <ul class="easy-cm-ul">
        <li>
          <div></div>
          <ul class="easy-cm-ul">
            <li>
              <div></div>
            </li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>

例如:

http://boho.image.alimmdn.com/github/p1.png?t=1524498301156

http://boho.image.alimmdn.com/github/p2.png

Demo Code

// gif 图源码
<template>
  <div id="app" @contextmenu="$easycm($event,$root)">
    <easy-cm :list="cmList"
             @ecmcb="test"
             :underline="true"
             :arrow="true">
    </easy-cm>
  </div>
</template>
<script>
export default {
  name: 'app',
  data () {
    return {
        // 配置数组
      cmList: [{
        text: 'Play Now',
        icon: 'iconfont icon-bofang'
      },{
        text: 'Play Next',
        icon: 'iconfont icon-xiayishou'
      },{
        text: 'More',
        children: [{
          text: 'Download',
          children: []
        },{
          text: 'Report'
        },{
          text: 'Other',
          icon: 'iconfont icon-bofang',
          children:[{
            text: 'Other-1'
          },{
            text: 'Other-2'
          },{
            text: 'Other-3'
          }]
        }]
      }]
    }
  },
  methods:{
      // 回调函数
    test(indexList){
      switch (indexList[0]){
        case 0:
          console.log('立即播放');
          break
        case 1:
          console.log('下一首播放')
          break
      }
    }
  }
}
</script>

vue-easycm's People

Contributors

boenfu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-easycm's Issues

请教请教

作者,你好,我是照着你的例子写的,但是每次我一右键那个按钮,那个菜单就闪一下就消失了,这是为什么呢?
image
image

建议对菜单项使用字符串 key 进行索引

如果不提供字符串 key 索引菜单项,在同菜单项目增加或者减少的时候需要编写多个不同菜单,因为现在我们对菜单处理的时候只能用索引确定它的功能。

请问如何获取到容器的数据?

使用场景为:
假设容器为图片,在图片上点击右键弹出操作菜单,请问如何才能获取到所点击的图片的数据?如何知道点击的是哪张图片?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.