当前位置:网站首页>鼠标右键 自定义
鼠标右键 自定义
2022-07-06 18:02:00 【阿六啊】

1.在需要添加右键的页面,绑定contextmenu事件(阻止浏览器默认事件,添加自定义事件)
<xx组件 @contextmenu.prevent.native="openMenu($event)">
2.在页面编写右键菜单的内容
<ul
v-show="visible"
:style="contextmenuStyle"
class="contextmenu"
>
<li @click="setBack">
置于底层
</li>
<li @click="setTop">
置于顶层
</li>
</ul>
3.定义属性变量
private contextmenuStyle: any={
}
private visible=false;
4.创建监听事件,来触发关闭右键菜单的方法
@Watch('visible')
private visibleChange () {
if (this.visible) {
// 显示的时候 添加一个点击事件 用于隐藏右键的内容
window.addEventListener('click', this.closeMenu);
} else {
window.removeEventListener('click', this.closeMenu);
}
}
5.打开和关闭右键菜单的两个方法
// 鼠标右键
private async openMenu (e) {
this.contextmenuStyle = {
left: e.offsetX + 'px',
top: e.offsetY + 'px'
};
this.visible = true;
}
private setBack () {
this.drawer.sendToBack();
}
private setTop () {
this.drawer.setTop();
}
private closeMenu () {
this.visible = false;
}
6.样式
<style lang='scss' scoped>
@import '[email protected]/css/variable';
.contextmenu {
margin: 0;
background: #eeeded;
opacity: 0.9;
z-index: 3000;
position: absolute;
list-style-type: none;
padding: 5px;
border-radius: 4px;
font-size: 12px;
color: #505050;
border: 1px solid $color-border;
box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);
}
.contextmenu li {
margin: 0;
padding: 2px 10px;
border-radius: 2px;
cursor: pointer;
}
.contextmenu li:hover {
background: $color-button-disabled-hover;
color: $color-basic;
}
</style>
边栏推荐
- Force buckle 1037 Effective boomerang
- NEON优化:性能优化经验总结
- [JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
- Failed to successfully launch or connect to a child MSBuild. exe process. Verify that the MSBuild. exe
- Yunna | work order management measures, how to carry out work order management
- 今日问题-2022/7/4 lambda体中修改String引用类型变量
- c语言—数组
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- json学习初体验–第三者jar包实现bean、List、map创json格式
- Implementation principle of waitgroup in golang
猜你喜欢

Go zero micro service practical series (IX. ultimate optimization of seckill performance)

Transplant DAC chip mcp4725 to nuc980

tansig和logsig的差异,为什么BP喜欢用tansig

让我们,从头到尾,通透网络I/O模型

HMM notes

JTAG debugging experience of arm bare board debugging

Force buckle 1037 Effective boomerang

Yunna | work order management measures, how to carry out work order management

Body mass index program, entry to write dead applet project

云呐|工单管理软件,工单管理软件APP
随机推荐
[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
AcWing 1142. 繁忙的都市 题解(最小生成树)
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
[advanced C language] 8 written questions of pointer
Share a general compilation method of so dynamic library
NEON优化:log10函数的优化案例
docker 方法安装mysql
WCF基金会
AI 从代码中自动生成注释文档
golang 基础 —— 数据类型
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
交叉验证如何防止过拟合
公钥\私人 ssh避password登陆
AcWing 904. 虫洞 题解(spfa求负环)
【C语言进阶篇】指针的8道笔试题
How to prevent overfitting in cross validation
What does security capability mean? What are the protection capabilities of different levels of ISO?
一起看看matlab工具箱内部是如何实现BP神经网络的
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion