/**
   * base64转为blob然后触发下载
   */
  base64toBlob(base64: string, filename: string, contentType = 'application/msword') {
    const url = `data:${contentType};base64,${base64}`;
    // console.log(url);
    fetch(url).then(res => res.blob())
      .then(blob => {
        const aTag = document.createElement('a');
        aTag.download = filename;
        aTag.href = URL.createObjectURL(blob);
        aTag.click();
        // 调用此方法,让浏览器知道不再保留对文件的引用。
        URL.revokeObjectURL(aTag.href);
      });
  }

发表评论