downloadFile(name, blob) { // 创建a标签 const link = document.createElement("a"); const url = URL.createObjectURL(blob); // download属性 link.setAttribute("download", name); // href链接 link.setAttribute("href", url); // 自执行点击事件 link.click(); document.body.removeChild(link); }, download(name, url) { // fetch抓取图片数据 fetch(url) .then(response => { if (response.status == 200) // 返回的.blob()为promise,然后生成了blob对象,此方法获得的blob对象包含了数据类型,十分方便 return response.blob(); throw new Error(status: ${response.status}.); }) .then(blob => { // 获取到blob对象 this.downloadFile(name, blob); }) .catch(error => { console.log("failed. cause:", error); }); },

相关文章:

  • 2021-11-23
  • 2021-10-03
  • 2021-08-12
  • 2022-01-27
  • 2021-12-16
  • 2021-11-19
  • 2021-10-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案