当前位置: 首页 > Web前端 > vue.js

记录html2canvas页面截图

时间:2023-03-31 15:08:15 vue.js

由于项目需要页面截图功能,所以找到了html2canvas插件

Share//jsasyncgoShare(){letdom=this.$refs["shareDom"];constres=awaithtml2canvas(dom,{width:parseInt(window.getComputedStyle(dom).width),height:parseInt(window.getComputedStyle(dom).height),allowTaint:true,taintTest:false,scale:window.devicePixelRatio,//设备像素比ignoreElements:(element)=>{//可从渲染中删除匹配的元素if(element.className==='exclude')returntrue;},})this.imgUrl=res.toDataURL()}最后是一张base64图片。