# td-contextmenu

> 自定义鼠标右键菜单

Latest version **2.0.2** (published 2022-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install td-contextmenu
pnpm add td-contextmenu
yarn add td-contextmenu
bun add td-contextmenu
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-02-10 |
| First published | 2022-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tandee |
| Maintainers | tandee |
| Keywords | 右键菜单, 自定义右键菜单 |

## Links

- npm: https://www.npmjs.com/package/td-contextmenu
- npm.io page: https://npm.io/package/td-contextmenu

## Recent versions

- 2.0.2 (latest) — 2022-02-10
- 2.0.1 — 2022-01-28
- 2.0.0 — 2022-01-28

## README

# 自定义右键菜单



[TOC]

## 参数

| 参数    | 说明 | 类型   | 可选值                                                       | 默认值 |
| ------- | ---- | ------ | ------------------------------------------------------------ | ------ |
| options | 参数 | object | { el, data, beforeShow, shown, beforeHide, hidden, beforeDestroy, destroyed } | —      |



### options说明

#### 参数

| 参数 | 说明                   | 类型   | 可选值        | 默认值 |
| ---- | ---------------------- | ------ | ------------- | ------ |
| el   | 元素节点和样式节点的id | string | mycontextmenu | —      |
| data | 自定义菜单结构数据     | array  | —             | —      |

#### 事件

| 事件名        | 说明             | 参数  |
| ------------- | ---------------- | ----- |
| beforeShow    | 显示前的回调函数 | event |
| shown         | 显示后的回调函数 | event |
| beforeHide    | 隐藏前的回调函数 | event |
| hidden        | 隐藏后的回调函数 | event |
| beforeDestroy | 销毁前的回调函数 | —     |
| destroyed     | 销毁后的回调函数 | —     |



## 事件

| 事件名     | 说明             | 参数  |
| ---------- | ---------------- | ----- |
| setData    | 设置菜单结构数据 | array |
| removeMenu | 清空菜单结构数据 | —     |
| show       | 显示右键菜单     | —     |
| hide       | 隐藏右键菜单     | —     |
| destroy    | 销毁组件         | —     |



## 使用

CDN引入


```html
<script src="https://unpkg.com/td-contextmenu/lib/index.min.js"></script>
```


```js
let contextmenu = new TdContextMenu({
    el: "mycontextmenu",
    data: [
        [
            {
                icon: "",
                title: "复制",
                func: null,
            },
            {
                icon: "",
                title: "粘贴",
                func: null,
            },
            {
                icon: "",
                title: "剪切",
                func: null,
            }
        ],
        [
        	{
                icon: "",
                title: "移动",
                func: null,
            	children: [
                    [
                        {
                            icon: "",
                            title: "上移",
                            func() {
                                console.log("开始上移")
                                // ...
                            },
                        },
                        {
                            icon: "",
                            title: "下移",
                            func: null,
                        }
                    ]
                ]
            }  
        ]
    ],
    beforeShow(e) {
        console.log("显示前的回调");
    },
    shown(e) {
        console.log("显示后的回调");
    },
    beforeHide(e) {
        console.log("隐藏前的回调");
    },
    hidden(e) {
        console.log("隐藏后的回调");
    },
    beforeDestroy() {
        console.log("销毁前的回调");
    },
    destroyed() {
        console.log("销毁后的回调");
    }
})
```

![image-20220126183215533](https://qiniudns.tannde.com//typora/202201261832299.png)


更新：
npm version patch
npm publish

---
_Source: https://npm.io/package/td-contextmenu · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
