如何在 ReactJS 中禁用 Canvas 中的右键单击。这是我尝试过但仍然无效的方法:
let Canvas = <canvas onContextMenu={(e)=> {e.preventDefault(); return false;}} height={500} width={500} ref="canvas"/>;
浏览器控制台中也会显示警告。
Warning: Returning
false
from an event handler is deprecated and will be ignored in a future release. Instead, manually call e.stopPropagation() or e.preventDefault(), as appropriate.
编辑:是的,它确实停止了 Canvas 上的右键单击功能,但我的问题是:我在左键单击时绘制了一个点,它也在右键单击时绘制,我想禁用它。
最佳答案
这个JS函数会阻止上下文菜单事件的冒泡,从而阻止上下文菜单出现:
canvas.oncontextmenu = function (e) {
e.preventDefault();
};
关于javascript - 在 React.JS 中禁用右键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35043748/