当前位置:   article > 正文

vue 文件流下载为.zip格式_vue下载zip文件流

vue下载zip文件流
  1. fileHandle(data, fileName) {
  2. let blob = new Blob([data], { type: 'application/zip' }//此处必须添加)
  3. let url = window.URL.createObjectURL(blob)
  4. const link = document.createElement('a') // 创建a标签
  5. link.href = url
  6. link.download = fileName // 重命名文件
  7. link.click()
  8. URL.revokeObjectURL(url) // 释放内存
  9. },
  10. DownloadFile(row) {
  11. let paymentId = row.cfbizPaymentEnrollment.ID
  12. let customerName = row.cfbizPaymentEnrollment.CUSTOMER_NAME
  13. doRestFileGet('service/payment/getAttachment?paymentId=' + paymentId + "&customerName=" + customerName,).then(result => {
  14. this.fileHandle(result.data, `${customerName}.zip`)
  15. })
  16. },
  17. // 请求
  18. export function doRestFileGet(url,params)
  19. {
  20. /* 自动添加sessionId */
  21. let sessionId = getToken();
  22. return service({
  23. url: url,
  24. method: 'get',
  25. responseType: 'blob', // 表明返回服务器返回的数据类型
  26. headers: {
  27. sessionId:sessionId,
  28. 'Content-Type': 'application/json; charset=UTF-8'
  29. },
  30. params:params
  31. }).catch(function (error) {
  32. console.log(error);
  33. });
  34. }

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号