获取后台传给前台的二进制流文件 ,前台实现下载

			//res 是后台返回的结果
			  const content = res.data;
              const blob = new Blob([content]);
              const fileName = "下载文件名"; //下载的文件名称
              if ('download' in document.createElement('a')) { // 非IE下载
                const elink = document.createElement('a');
                elink.download = fileName;
                elink.style.display = 'none';
                elink.href = URL.createObjectURL(blob);
                document.body.appendChild(elink);
                elink.click();
                URL.revokeObjectURL(elink.href); // 释放URL 对象
                document.body.removeChild(elink);
              } else { // IE10+下载
                 navigator.msSaveBlob(blob, fileName);
              } 

猜你喜欢

转载自blog.csdn.net/u013746071/article/details/87864085