Vue禁止用户复制文案 + 兼容 IE

vue必须要加载完才可以操作dom,或者在mounted和created时使用this.$nextTick方法,使dom生成后进行相关操作。

 created() {
      this.$nextTick(() => {
        // 禁用右键
        document.oncontextmenu = new Function("event.returnValue=false");
        // 禁用选择
        document.onselectstart = new Function("event.returnValue=false");
      });
    }

兼容 IE

<body oncontextmenu="return false" onselectstart="return false" ondragstart="return false"  oncopy=document.selection.empty()</body>
  • 禁止鼠标右键:oncontextmenu="return false";
  • 禁止选择:onselectstart="return false;
  • 禁止拖放:ondragstart="return false";
  • 禁止拷贝:oncopy=document.selection.empty() ;
  • 禁止粘贴:<&input type=text onpaste="return false"> 试试?
posted @ 2020-08-03 15:30  Echoyya、  阅读(585)  评论(0编辑  收藏  举报