0
点赞
收藏
分享

微信扫一扫

vue页面事件/鼠标事件禁用

大南瓜鸭 2022-03-30 阅读 94

某个dom的鼠标右键禁用

<div @contextmenu.prevent="handlePaste($event)">

methods:{
	// 禁用鼠标右键点击事件
 handlePaste(event){
  event.preventDefault();
  return false;
 },
}

整个页面的事件禁用

created(){
this.stopF5Refresh();
},
methods:{
stopF5Refresh() {
      document.onkeydown = function(e) {
        var evt = window.event || e;
        var code = evt.keyCode || evt.which;
        //屏蔽F1---F12
        if (code > 111 && code < 124) {
          if (evt.preventDefault) {
            evt.preventDefault();
          } else {
            evt.keyCode = 0;
            evt.returnValue = false;
          }
        }
      };
      //禁止鼠标右键菜单
      document.oncontextmenu = function(e) {
        return false;
      };
      //阻止后退的所有动作,包括 键盘、鼠标手势等产生的后退动作。
      history.pushState(null, null, window.location.href);
      window.addEventListener("popstate", function() {
        history.pushState(null, null, window.location.href);
      });
    },
}
举报

相关推荐

0 条评论