npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v-contextmenu-directive

v2.0.2

Published

基于 Vue2.x 的右键菜单插件

Downloads

6

Readme

🌈 v-contextmenu-directive

基于 Vue2.x 的右键菜单插件。

DEMO: https://pipipi-pikachu.github.io/v-contextmenu-directive/dist/

📦 安 装

npm install v-contextmenu-directive
# or
yarn add v-contextmenu-directive

📚 如何使用?

import Vue from 'vue'
import Contextmenu from 'v-contextmenu-directive'

Vue.use(Contextmenu)

基础用法:

<!-- template -->
<div v-contextmenu="contextmenus"></div>
// script
methods: {
  contextmenus() {
    return [
      {
        text: '剪切',
        subText: 'Ctrl + X',
      },
      {
        text: '复制',
        subText: 'Ctrl + C',
      },
      {
        text: '粘贴',
        subText: 'Ctrl + V',
      },
      { divider: true },
      {
        text: '删除',
        subText: 'Delete',
      },
    ]
  }
},

多级菜单:

methods: {
  contextmenus() {
    return [
      {
        text: '二级菜单',
        children: [
          { text: '子菜单1' },
          { text: '子菜单2' },
          {
            text: '三级菜单',
            children: [
              { text: '子菜单1' },
              { text: '子菜单2' },
            ],
          },
        ],
      },
    ]
  }
}

事件和点击对象:

<!-- template -->
<div v-contextmenu="el => contextmenus(el)">
  {{msg}}
</div>
// script
methods: {
  contextmenus(el) {

    // 获取触发右键菜单的dom;与action中的el一致
    // 注意:一般情况下你不应该向contextmenus方法传递动态参数,因为它不会自动更新,正确的做法是向触发右键菜单的dom上绑定dataset,然后在这里通过el.dataset来获取动态的值
    console.log(el)

    // 你可以在这里通过 return null 来禁用右键菜单
    // return null

    return [
      {
        text: '剪切',
        subText: 'Ctrl + X',
        action: () => this.msg = '你点击了剪切'
      },
      {
        text: '复制',
        subText: 'Ctrl + C',
        action: el => {
          this.msg = '你点击了复制'
          console.log(el)
        }
      },
    ]
  }
}

dom激活右键菜单的状态:

挂载指令的dom在右键菜单被激活的情况下,会被添加一个contextmenu-active的class

<!-- template -->
<div id="app" v-contextmenu="contextmenus"></div>
#app {
  background-color: #fff;
}
#app.contextmenu-active {
  background-color: #f5f5f5;
}

主题:

右键菜单默认主题为light,你可以添加dark修饰符来使用dark主题

<!-- template -->
<div id="app" v-contextmenu.dark="contextmenus"></div>

📒 完整参数

| prop | type | 描述 | |----------------|----------|-----------------------------------------------| | text | string | 菜单项文字 | | subText | string | 菜单项文字补充 | | action | function | 菜单项点击后执行的方法 | | divider | bool | 分割线,与其他参数不共存 | | children | array | 子菜单 | | disable | bool | 禁用菜单项 | | hide | bool | 隐藏菜单项 |