useCORS 是 html2canvas 的一个配置选项,它用于处理跨域资源共享(CORS)问题。
当你试图抓取包含跨域资源(例如,从不同的域、协议或端口加载的图片)的网页时,你可能会遇到安全限制问题。在这种情况下,你可以设置 useCORS 为 true 来允许 html2canvas 使用CORS代理来下载图片资源。
const options = {
backgroundColor: null,
useCORS: true,
};
html2canvas(canvasBox, options).then((canvas) => {
const base64 = canvas.toDataURL('image/png');
});