html2canvas(that.$app, { 'width' : that.$app.get(0).offsetWidth, 'height' : that.$app.get(0).scrollHeight, 'background' : '#fff', 'scale': window.devicePixelRatio || 1, 'onclone' : function(cloneDoc) { }, onrendered : function(canvas) { var base64Data = canvas.toDataURL("image/png"); // 创建a标签 并设置其相关属性,最后触发其点击事件 let a = document.createElement("a") let clickEvent = document.createEvent("MouseEvents"); a.setAttribute("href", base64Data) a.setAttribute("download", "绩效下载") a.setAttribute("target", '_blank') clickEvent.initEvent('click', true, true) a.dispatchEvent(clickEvent); } });
标签:canvas,app,setAttribute,html2canvas,clickEvent,document,下载,图片 From: https://www.cnblogs.com/qiao20/p/16962995.html