我一直在开发一个使用 html-to-image 库将 div 下载为图像的功能。它在 Android 手机上运行良好,但使用 IOS 手机时,它只下载文本并跳过图像。请问我该如何解决这个问题?
这是我的IOS下载功能。
async function IosDownloadImages(){
try{
let dataUrl = await htmlToImage.toJpeg(downloadable.current);
setTimeout(function(){
console.log(dataUrl)
setDownloadStage(86);
const U = document.createElement('a');
let ran = randomNumberInRange(0,999);
U.download = "Image"+ran;
setDownloadStage(90);
U.href = dataUrl;
U.click();
return "success";
},2500);
}catch(e){
return e;
}
}
试试这个:
async function IosDownloadImages(){
try{
let blob = await Promise.all([
htmlToImage.toBlob(downloadable.current),
htmlToImage.toBlob(downloadable.current)
]).then((res)=>res[1] as Blob);
setDownloadStage(86);
const url = window.URL.createObjectURL(blob)
let ran = randomNumberInRange(0,999);
setDownloadStage(90);
const link = document.createElement('a');
link.href = url;
link.download = "Image"+ran;
link.click();
return "success";
}catch(e){
return e;
}