鼠标右键点击事件
方法一
.prevent可以阻止弹出默认的窗口
<el-button @contextmenu.prevent="clickRight()">保存</el-button>
方法二
通过鼠标的mousedown事件。在鼠标按下的操作中 我们鼠标左键是 0 中间滚轮是 1 右键 是2
<el-button @click.right="clickRight()">保存</el-button>
方法三
document.addEventListener("mousedown", (e) => {
if (e.button == 1) {
console.log("你按下了鼠标滚轮!");
} else if (e.button == 2) {
console.log("你按下了鼠标右键!");
} else {
console.log("你按下了鼠标左键!"); //按左键没有反应
}
e.preventDefault();
});
方法四 (contextmenu)
document.addEventListener("contextmenu", (e) => {
this.clickRight();
e.preventDefault(); // 阻止弹出默认的右键窗口
});