vue实现可防止删除的水印组件示例代码
代码语言:html
所属分类:其他
代码描述:vue实现可防止删除的水印组件示例代码,采用MutationObserver监听dom修改操作防止水印被删除。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Watermark Component</title> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue@2.6.1-dev.js"></script> </head> <body> <div id="app"> <watermark> <div> <!-- 这里是您的页面内容 --> <h1>Hello, World!</h1> </div> </watermark> </div> <script> var observer=null; // 定义水印组件 Vue.component('watermark', { mounted() { var that=this; observer = new MutationObserver((entity) => { console.log(entity) that.drawWatermark(); }); this.drawWatermark(); window.addEventListener('scroll', this.drawWatermark); window.addEventListener('resize', this.drawWatermark); }, beforeDestroy() { window.removeEventListener('scroll', this.drawWatermark); window.removeEventListener('resize', this.drawWatermark); }, methods: { drawWatermark() { const ins = document.querySelector('.watermark'); //如果标签在 if (ins) { return; } if(observer!=null){ console.log("停止监听") observer.disconnect(); } const canvas = document.createElement('canvas'); canvas.classList.a.........完整代码请登录后点击上方下载按钮下载查看
网友评论0