在回显图片后,给img标签动态的加上crossOrigin="anonymous"属性
然后
服务端开启跨域response.setHeader("Access-Control-Allow-Origin","*");
并且开启CORS(重要)
前端等图片加载完后再截图(重要)
截图JS代码(会来百度的都看的懂):useCORS记得开起来,很重要!!!
html2canvas($("#capture")[0], { useCORS: true, backgroundColor:null, }).then(canvas => { let imgUri = canvas.toDataURL("image/png").replace("image/png","image/octet-stream") console.log(imgUri);