useCORS 是 html2canvas 的一個(gè)配置選項(xiàng),它用于處理跨域資源共享(CORS)問題。
當(dāng)你試圖抓取包含跨域資源(例如,從不同的域、協(xié)議或端口加載的圖片)的網(wǎng)頁時(shí),你可能會(huì)遇到安全限制問題。在這種情況下,你可以設(shè)置 useCORS 為 true 來允許 html2canvas 使用CORS代理來下載圖片資源。
const options = {
backgroundColor: null,
useCORS: true,
};
html2canvas(canvasBox, options).then((canvas) => {
const base64 = canvas.toDataURL('image/png');
});