// row是当前行的数据
const downloadImg = (row) => {
          if(row.lqiPhoto !== null) {
            let link = document.createElement("a")
            link.style.display = 'none'
            link.href = row.lqiPhoto
            link.setAttribute('download', '导出img')
            document.body.appendChild(link)
            link.click()
            console.log("🚀 ~ file: index.vue:213 ~ downloadImg ~ link:", link)
          } else {
                message.warning('该行没有附件')
          }
        }

vue3下载文件流

// 后端返回的

const download = async (row) => {
  // 接口数据,返回的文件流
  const {data} = await downloadcode(row.bucketName,row.fileName)
  
  let blob = new Blob([data]);
  let downloadElement = document.createElement("a");
  let href = window.URL.createObjectURL(blob); //创建下载的链接
  downloadElement.href = href;
  downloadElement.download = row.original; //下载后文件名
  document.body.appendChild(downloadElement);
  downloadElement.click(); //点击下载
  document.body.removeChild(downloadElement); //下载完成移除元素
  window.URL.revokeObjectURL(href); //释放掉blob对象
} 

Logo

前往低代码交流专区

更多推荐