import html2Canvas from 'html2canvas' import download from "@/utils/download"; //download.js export default{ install (Vue, Function.prototype.getpdf = function (id,callback) {// the browser scroll bar is set to the top otherwise blank window.pageyoffset = 0; document.documentElement.scrollTop = 0; document.body.scrollTop = 0; Html2Canvas (document.querySelector(id), {// allowTaint: true, useCORS:true,// Allow cross-domain scrollX: }). Then (function (canvas) {let contentWidth = canvas. Width let contentHeight = canvas = contentWidth / 592.28 * 841.89 Let leftHeight = contentHeight let position = 0 let imgWidth = 595.28 let imgHeight = ContentWidth * contentHeight //2, Add crossorigin="anonymous" to every <img> tag contained in the canvas DOM; Let pageData = Canvas. ToDataURL ('image/ JPEG ', 1.0) Download (pageData, title + ".png", "image/png");Copy the code
1. Add useCORS:true;
2. Give each one contained in the DOM to generate canvasTag crossorigin=”anonymous”;
3, make sure your image CDN server supports CORS Access, that is, will return access-Control-Allow-Origin headers;